Solved qRegisterMetaType() : QMap<QString,long long int>
-
Hi,
I'm trying to passQMap<QString,long long unsigned int> or QHash<QString,long long unsigned int>
from one class to another using Signal/Slot but i have this output :
QObject::connect: Cannot queue arguments of type 'QMap<QString,long long unsigned int>' (Make sure 'QMap<QString,long long unsigned int>' is registered using qRegisterMetaType().)
I googled this and found some related topics but can't really understand when/where/how to register my QMap, can someone put me on the right track please ?
I also wonder if there is another simple method to exchange(using signal/slot) a pair of values (Qstring name, int size)
Thx in advance
-
@LeLev said in qRegisterMetaType() : QMap<QString,long long int>:
when/where/how to register my QMap
When: when you need to pass arguments to a queued connection or to enable creation of objects at run-time
Where: before using any of the above. Normally it's done directly in themain()
How: Just callqRegisterMetaType<QMap<QString,long long unsigned int> >();
I also wonder if there is another simple method to exchange(using signal/slot) a pair of values (Qstring name, int size)
QPair<QString,int>
-
@VRonin thank you very much.
-
I tought i was good to go with @VRonin s answer but after putting
qRegisterMetaType<QMap<QString,long long unsigned int> >()
in my main.cpp or just before the QObject::connect i still have the same error output when the signal is emitted;
-
@LeLev said in qRegisterMetaType() : QMap<QString,long long int>:
in my main.cpp
Where exactly? Inside main function?
-
@LeLev
I believe, to pass qRegisterMetaType via QueuedConnection you have to register it with a name:
qRegisterMetaType<MyClass>("MyClass");
-
hi;
@jsulm said in qRegisterMetaType() : QMap<QString,long long int>:Where exactly? Inside main function?
I tryed before the engine.load , after it, before object creation, after..
int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); // qRegisterMetaType<QMap<QString,long long unsigned int> >(); Machine m; SysLogTest logger; Sftp_user sftp; // qRegisterMetaType<QMap<QString,long long unsigned int> >(); QQmlApplicationEngine engine; engine.rootContext()->setContextProperty("sftp",&sftp); engine.rootContext()->setContextProperty("machine",&m); engine.rootContext()->setContextProperty("logger",&logger); // qRegisterMetaType<QMap<QString,long long unsigned int> >(); engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); // qRegisterMetaType<QMap<QString,long long unsigned int> >(); if (engine.rootObjects().isEmpty()) return -1; return app.exec(); }
-
hello,
@J.Hilk said in qRegisterMetaType() : QMap<QString,long long int>:I believe, to pass qRegisterMetaType via QueuedConnection you have to register it with a name:
Sorry i don't understand. The error i have is :
Make sure 'QMap<QString,long long unsigned int>' is registered using qRegisterMetaType().if i do what you suggested :
qRegisterMetaType<MyClass>("MyClass");
output >>>
C:\Qt\5.11.0\mingw53_32\include\QtCore\qobject.h:449: erreur : 'QObject::QObject(const QObject&)' is private Q_DISABLE_COPY(QObject) ^
-
@LeLev
An excerpt from my latest project, maybe it will help you.
QVector<quint16>, uint32_t, int32_, uint8_t and TerminalIO::serviceErrors & QModbusDevice::Error( both enumerations) are passed Queued via Signal/Slotint main(int argc, char *argv[]) { qRegisterMetaType<QVector<quint16> >("QVector<quint16>"); qRegisterMetaType<Datagram>(); qRegisterMetaType<QLowEnergyDescriptor>(); qRegisterMetaType<QLowEnergyCharacteristic>(); qRegisterMetaType<TerminalIO::serviceErrors>("serviceErrors"); qRegisterMetaType<uint32_t>("uint32_t"); qRegisterMetaType<int32_t>("int32_t"); qRegisterMetaType<uint8_t>("uint8_t"); #if defined(Q_OS_WIN) || defined(Q_OS_MACOS) qRegisterMetaType<QModbusDevice::Error>("Error"); #endif QGuiApplication app(argc, argv); ... QQmlApplicationEngine engine; ... engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); return app.exec(); }
-
@J.Hilk Perfect thx!
this workedqRegisterMetaType<QMap<QString,long long unsigned int> >("QMap<QString,long long unsigned int>");