Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. Chinese
  4. QSerialPort线程
Forum Updated to NodeBB v4.3 + New Features

QSerialPort线程

Scheduled Pinned Locked Moved Unsolved Chinese
4 Posts 4 Posters 1.3k 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.
  • L Offline
    L Offline
    linxisuo
    wrote on last edited by
    #1

    请问大家 有遇到过这种情况吗?
    使用QSerialPort进行串口通信,在主线程中new一个QSerialPort,并连接好指定串口。在主线程中可以正常通信,传入子线程中就不能使用。
    望解答,谢谢

    1 Reply Last reply
    0
    • F Offline
      F Offline
      faweideniu
      wrote on last edited by
      #2

      @linxisuo said in QSerialPort线程:

      使用QSerialPort进行串口通信,在主线程中new一个QSerialPort,并连接好指定串口。在主线程中可以正常通信,传入子线程中就不能使用。

      QT大多数的类都不是线程安全的,需要在主线程使用

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Magic7
        wrote on last edited by
        #3

        QT线程中run需要独立创建QSerialPort,并且start的时候不能占用端口。

        1 Reply Last reply
        0
        • LoongPL Offline
          LoongPL Offline
          LoongP
          wrote on last edited by
          #4

          QSerialPort为IO设备,不要进行跨线程操作。最好的方法如楼上所说,在子线程中实例化该对象,例如:继承QThread的子类,应该在run()函数中定义并实例化QSerialPort。

          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