How to invoke qRegisterMetaType when run thread with pointer to another thread?
-
Hello, I've never developed under Qt, but today I faced to an issue: when I run bitcoin-abc I get message in terminal: "QVariant::load: unknown user type with name BitcoinUnits::Unit." I found the warning in documentation that need to use qRegisterMetaType(), but the code is not simple enough for fix it by novice as I am.
There is comment in src/qt/bitcoin.cpp:// Note on how Qt works: it tries to directly invoke methods if the signal // is emitted on the same thread that the target object 'lives' on. // But if the target object 'lives' on another thread (executor here does) // the SLOT will be invoked asynchronously at a later time in the thread // of the target object. So.. we pass a pointer around. If you pass // a reference around (even if it's non-const) you'll get Qt generating // code to copy-construct the parameter in question (Q_DECLARE_METATYPE // and qRegisterMetaType generate this code). For the Config class, // which is noncopyable, we can't do this. So.. we have to pass // pointers to Config around. Make sure Config &/Config * isn't a // temporary (eg it lives somewhere aside from the stack) or this will // crash because initialize() gets executed in another thread at some // unspecified time (after) requestedInitialize() is emitted! connect(this, &BitcoinApplication::requestedInitialize, executor, &BitcoinABC::initialize); connect(this, &BitcoinApplication::requestedShutdown, executor, &BitcoinABC::shutdown); connect(window, SIGNAL(requestedRestart(QStringList)), executor, SLOT(restart(QStringList))); /* make sure executor object is deleted in its own thread */ connect(coreThread, &QThread::finished, executor, &QObject::deleteLater); coreThread->start();
I think, that, here we run QT Application with a pointer to BitcoinApplication instead of sending signals to a slot, and need to check if qRegisterMetaType() is actually invoked.
Could you read and give some advice?
Here exact link to this strange code in BTC-ABC
Here it is bitcoinunits.cppMy system is Devuan Linux, g++ version 12.2, qt version 5.15.8.
-
Just call it in main if you don't find another / better place.