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. QDebug print out "QObject::startTimer: Timers can only be used with threads started with QThread" when I run QModbusClient::sendReadRequest in std::thread
Forum Updated to NodeBB v4.3 + New Features

QDebug print out "QObject::startTimer: Timers can only be used with threads started with QThread" when I run QModbusClient::sendReadRequest in std::thread

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 645 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.
  • H Offline
    H Offline
    HuXiaoer
    wrote on last edited by
    #1

    I use Qt5.9.8 and my code like this:

    int main(int argc, char *argv[])
    {
        QCoreApplication app(argc, argv);
       std::thread([] {
    			//QModbusRtuSerialMaster ->connectDevice
                           //run QModbusRtuSerialMaster ->sendReadRequest 
    		}).detach();
        return app.exec();
    }
    
    jsulmJ 1 Reply Last reply
    0
    • H HuXiaoer

      I use Qt5.9.8 and my code like this:

      int main(int argc, char *argv[])
      {
          QCoreApplication app(argc, argv);
         std::thread([] {
      			//QModbusRtuSerialMaster ->connectDevice
                             //run QModbusRtuSerialMaster ->sendReadRequest 
      		}).detach();
          return app.exec();
      }
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @HuXiaoer Why don't you use QThread instead of std::thread?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      H 1 Reply Last reply
      0
      • jsulmJ jsulm

        @HuXiaoer Why don't you use QThread instead of std::thread?

        H Offline
        H Offline
        HuXiaoer
        wrote on last edited by
        #3

        @jsulm Why The SendReadRequest binding slot function could not be called when I use QThread

        D jsulmJ 2 Replies Last reply
        0
        • H HuXiaoer

          @jsulm Why The SendReadRequest binding slot function could not be called when I use QThread

          D Offline
          D Offline
          Dariusz
          wrote on last edited by
          #4

          @HuXiaoer I don't know if this help... but what about simply >

          QThreadPool pool;
          QtConcurrent::run(&pool,[&]() {doUrstuffHere});
          

          ?
          Or maybe u need QMetaObject::invokeMethod(object,[&](){},Qt::QueuedConnection);
          ?

          1 Reply Last reply
          0
          • H HuXiaoer

            @jsulm Why The SendReadRequest binding slot function could not be called when I use QThread

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @HuXiaoer said in QDebug print out "QObject::startTimer: Timers can only be used with threads started with QThread" when I run QModbusClient::sendReadRequest in std::thread:

            Why The SendReadRequest binding slot function could not be called when I use QThread

            I don't know what this means. Can you please explain better?
            Also, why do you need threads at all? QtModbus has an asynchronous API...

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            3

            • Login

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