Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to invoke qRegisterMetaType when run thread with pointer to another thread?
Forum Updated to NodeBB v4.3 + New Features

How to invoke qRegisterMetaType when run thread with pointer to another thread?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 168 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    younicoin
    wrote on last edited by younicoin
    #1

    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.cpp

    My system is Devuan Linux, g++ version 12.2, qt version 5.15.8.

    Christian EhrlicherC 1 Reply Last reply
    0
    • Y younicoin

      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.cpp

      My system is Devuan Linux, g++ version 12.2, qt version 5.15.8.

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Just call it in main if you don't find another / better place.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved