我必须使用ActiveQt(qt 4.8.6 windows7)。我遇到了进程外服务器(.exe)的问题。它已成功注册,它通过插槽响应容器的信号,但我不能让服务器发出信号(或让容器接受它们)。
专业档案:
TARGET = object_mkpa
TEMPLATE = app
CONFIG += qt warn_off qaxserver
RC_FILE = qaxserver.rc
DEF_FILE = qaxserver.def
SOURCES += src/object_mkpa.cpp \
src/main.cpp
HEADERS += src/object_mkpa.h
头:
#include <QObject>
#include <QAxBindable>
class Object_mkpa : public QObject, public QAxBindable
{
Q_OBJECT
Q_CLASSINFO("RegisterObject", "yes")
public:
Object_mkpa(QObject* parent = 0 );
public slots:
...
signals:
...
};
源:
#include "object_mkpa.h"
#include <QAxFactory>
Object_mkpa::Object_mkpa(QObject* parent) : QObject(parent) { }
QAXFACTORY_DEFAULT(Object_mkpa, //widget class
"{69dfccf5-697f-497f-8aa9-d1ecfb64c1bf}", //class ID
"{e276cc69-3bf8-4932-b341-bdcb1045901b}", //interface ID
"{60b215f0-7f16-4f79-bac8-6b8d3cb14a00}", //event interface
"{110d3945-cfe7-4ae7-872c-02757e8dde91}", //type library ID
"{88dec6e0-4a5a-4c0b-bcdd-3f18dea9d86d}") //app ID
...
和main,这实际上不是必需的(它甚至可以执行吗?..)
#include "object_mkpa.h"
#include <QApplication>
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
return app.exec();
}
我测试过程中服务器(dll)并在那里工作信号,但它有另一个问题 - 它为每个使用dll的容器实例化COM-object。我认为它应该如何(这与我需要的相反),但如果你知道任何黑客 - 请告诉我。
与进程外的差异是缺少main.cpp并稍微改变.pro文件
TARGET = object_mkpa_dll
TEMPLATE = lib
CONFIG += qt warn_off dll qaxserver
RC_FILE = qaxserver.rc
DEF_FILE = qaxserver.def
LIBS += -lQAxServerd
HEADERS += \
object_mkpa_dll.h
SOURCES += \
object_mkpa_dll.cpp
使用qt creator本机构建步骤构建后,我确实在.exe或.dll上使用dumpcpp,并将生成的文件复制到客户端目录。
.pro文件的重要部分:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TEMPLATE = app
CONFIG += qaxcontainer
最后这就是我如何使用它:
object_mkpaLib::Object_mkpa interface; //this is in class declaration
QObject::connect(&interface, SIGNAL(test(int)), SLOT(testTester(int)));
QObject::connect(this, SIGNAL(test(QString)), &interface, SLOT(test2(QString)));