Details
-
Bug
-
Resolution: Fixed
-
P2: Important
-
6.5.4, 6.6.2
-
c342f12bf (dev), 8c0a8e82d (6.7), 23f754d9c (tqtc/lts-6.5)
Description
Server-side sample code (may need different UUIDs):
class MyActiveX : public QObject { Q_OBJECT Q_CLASSINFO("ClassID", "{DF16845C-92CD-4AAB-A982-EB9840E74669}") Q_CLASSINFO("InterfaceID", "{616F620B-91C5-4410-A74E-6B81C76FFFE0}") Q_CLASSINFO("EventsID", "{E1816BBA-BF5D-4A31-9855-D6BA432055FF}") Q_CLASSINFO("Aggregatable", "no") Q_CLASSINFO("RegisterObject", "yes") Q_CLASSINFO("Insertable", "yes") public: MyActiveX(QObject* parent) : QObject(parent) {} public slots: QVariantList test1() { QVariantList result; result.append("Test"); result.append(1.); return result; } QVariantList test2() { QVariantList result; result.append(1.); result.append("Test"); return result; } }; #include "main.moc" QAXFACTORY_BEGIN( "{EC08F8FC-2754-47AB-8EFE-56A54057F34E}", // type library ID "{A095BA0C-224F-4933-A458-2DD7F6B85D8F}") // application ID QAXCLASS(MyActiveX) QAXFACTORY_END()
Client-side sample code (may need a different COM object name for QAxObject)
int main(int argc, char *argv[]) { QApplication app(argc, argv); QAxObject* obj = new QAxObject("simpleax.MyActiveX", &app); if(!obj->isNull()) { std::cout << "Object created" << std::endl; qDebug() << "Test1:" << obj->dynamicCall("test1()"); qDebug() << "Test2:" << obj->dynamicCall("test2()"); } else { std::cout << "Object not found" << std::endl; } return 0; }
So in 5.15, both methods work well. Build the server first and run it with -regsever. Then run the client and it will output:
Object created Test1: QVariant(QVariantList, (QVariant(QString, "Test"), QVariant(double, 1))) Test2: QVariant(QVariantList, (QVariant(double, 1), QVariant(QString, "Test")))
But in 6.5.4 or 6.6.2, the QVariantList that has string appended as the first element (what test1() returns) does not work anymore. It returns a list of invalid QVariants. Also, the size of QVariantList is obviously not correct. Client output:
Object created Test1: QVariant(QVariantList, (QVariant(QVariantList, (QVariant(Invalid), QVariant(Invalid), QVariant(Invalid), QVariant(Invalid))), QVariant(QVariantList, (QVariant(Invalid), QVariant(Invalid), QVariant(Invalid), QVariant(Invalid))))) Test2: QVariant(QVariantList, (QVariant(double, 1), QVariant(QString, "Test")))
Currently, a workaround seems to be using QStringList instead of QVariantList. If "test1()" is rewritten as:
QStringList test1() { QStringList result; result.append("Test"); result.append(QString::fromLocal8Bit("1.")); return result; }
then it works normally. The output for it is as expected:
Test1: QVariant(QStringList, ("Test", "1."))
But such workaround affects the flexibility. One has to do extra conversion on server and/or client side. It's desirable to restore Qt5.15 behavior.