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 modbus runs in other threads
Forum Updated to NodeBB v4.3 + New Features

How modbus runs in other threads

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 202 Views 1 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.
  • X Offline
    X Offline
    xiaguangbo
    wrote on last edited by
    #1

    The current method used is to have classes that use 'QModbusRtuSerialMaster' inherit QObject, which is referred to as' A 'here. Declare 'QThread * t1;' in 'class MainWindow', and then use 't1=new QThread; A.moveToThread (t1);' in the construction method. This is feasible, but if 't1' is not a pointer, using 'A.moveToThread (&t1);' will not run properly and no data will be visible on the serial port

    If 'A' inherits' QRunnable 'and runs QModbusRtuSerialMaster in' run() override ', it is also abnormal.

    Using QtConcurrent:: run is also abnormal, why is this

    Axel SpoerlA 1 Reply Last reply
    0
    • X xiaguangbo

      The current method used is to have classes that use 'QModbusRtuSerialMaster' inherit QObject, which is referred to as' A 'here. Declare 'QThread * t1;' in 'class MainWindow', and then use 't1=new QThread; A.moveToThread (t1);' in the construction method. This is feasible, but if 't1' is not a pointer, using 'A.moveToThread (&t1);' will not run properly and no data will be visible on the serial port

      If 'A' inherits' QRunnable 'and runs QModbusRtuSerialMaster in' run() override ', it is also abnormal.

      Using QtConcurrent:: run is also abnormal, why is this

      Axel SpoerlA Offline
      Axel SpoerlA Offline
      Axel Spoerl
      Moderators
      wrote on last edited by
      #2

      @xiaguangbo
      It's a bit difficult to figure out what you really mean. Before you post, it helps to imagine what if reader without any contextual knowledge of your problem will understand it.

      Generally it doesn't make any difference if the QThreadis heap or stack allocated.

      will not run properly

      What do you mean by "properly"? What exactly do you expect?
      Probably the QThreadgoes out of scope before the operation is finished.
      Has t1.start();been called at all?

      Maybe post your entire code and use code block quotation for better readability.

      Software Engineer
      The Qt Company, Oslo

      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