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. Problem with running timer in another thread
Qt 6.11 is out! See what's new in the release blog

Problem with running timer in another thread

Scheduled Pinned Locked Moved Solved General and Desktop
44 Posts 9 Posters 34.0k Views 3 Watching
  • 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.
  • D Damian7546

    @Christian-Ehrlicher I expected such answers: "simply use QSerialPort and proper signals & slots." . I have project realized in this way.
    But as part of learning (main goal of the project) programming and uing threads I would like to use threads this time to serial communication, and run example considered in this topic.

    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by JonB
    #41

    @Damian7546
    Then by choosing to use threads where they are probably not needed you (or the original author) have ended up with a problem using threads, possibly because the original code was not well written for threads. Which tells you a lot... ! Just saying.

    1 Reply Last reply
    0
    • D Damian7546

      @Christian-Ehrlicher I expected such answers: "simply use QSerialPort and proper signals & slots." . I have project realized in this way.
      But as part of learning (main goal of the project) programming and uing threads I would like to use threads this time to serial communication, and run example considered in this topic.

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #42

      @Damian7546 said in Problem with running timer in another thread:

      But as part of learning (main goal of the project) programming and uing threads I would like to use threads this time to serial communication, and run example considered in this topic.

      Then you can look, for example, at Qt's Blocking Serial Port Examples:

      (Sender)

      • https://doc.qt.io/qt-6/qtserialport-blockingsender-example.html

      (Receiver)

      • https://doc.qt.io/qt-6/qtserialport-blockingreceiver-example.html

      Or you use some non-Qt implementation of serial port communication, such as serial_port from Boost.ASIO library.
      (makes little sense, since you are already using Qt which provides all that stuff... but for learning purposes it's fine to look at different techniques)

      • https://www.boost.org/doc/libs/1_84_0/doc/html/boost_asio/overview/serial_ports.html

      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      0
      • D Damian7546

        @Christian-Ehrlicher I expected such answers: "simply use QSerialPort and proper signals & slots." . I have project realized in this way.
        But as part of learning (main goal of the project) programming and uing threads I would like to use threads this time to serial communication, and run example considered in this topic.

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

        @Damian7546 said in Problem with running timer in another thread:

        But as part of learning (main goal of the project) programming and uing threads I would like to use threads this time to serial

        Then look at the Qt documentation for Qt threads and it's examples instead some obscure git projects.

        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
        1
        • D Offline
          D Offline
          Damian7546
          wrote on last edited by Damian7546
          #44

          Problem with QObject::startTimer: Timers cannot be started from another thread Solved!

          I changed:

          -All entries of the connect function, from:

          connect(this, &CctalkLinkController::openPortInWorker, serial_worker_.data(), &SerialWorker::openPort, Qt::QueuedConnection);
          

          to:

          connect(this, &CctalkLinkController::openPortInWorker, serial_worker_, &SerialWorker::openPort, Qt::QueuedConnection);
          

          Because I don't have any idea what is data() ?

          And like suggested @J.Hilk in CctalkLinkController I changed:

          CctalkLinkController::CctalkLinkController()
          {
              serial_worker_ = new SerialWorker();
          

          to

          CctalkLinkController::CctalkLinkController(QObject *parent) : QObject(parent), serial_worker_{new SerialWorker(this)}
          {
          
          1 Reply Last reply
          0
          • D Damian7546 has marked this topic as solved on
          • D Damian7546 has marked this topic as solved on
          • D Damian7546 has marked this topic as solved on

          • Login

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