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. Main thread call from another thread
Forum Update on Monday, May 27th 2025

Main thread call from another thread

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 393 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
    Loc888
    wrote on last edited by Loc888
    #1

    I am trying to post an event, and call the main thread, since in opencv gui function don't work otherwise. I tried also to move the object to the main thread by using

    moveToThread(QGuiApplication::instance()->thread());
    

    but the output i get isn't showing any results

    currentThread:  QThread(0x22fd70) -- QGuiApplication::instance:  QThread(0x2fcc70)
    

    Events, signals and also this move to thread doesn't fix the issue.. I have to make a signal to the main thread, to execute a function, how to do it then?

    jsulmJ 1 Reply Last reply
    0
    • L Loc888

      I am trying to post an event, and call the main thread, since in opencv gui function don't work otherwise. I tried also to move the object to the main thread by using

      moveToThread(QGuiApplication::instance()->thread());
      

      but the output i get isn't showing any results

      currentThread:  QThread(0x22fd70) -- QGuiApplication::instance:  QThread(0x2fcc70)
      

      Events, signals and also this move to thread doesn't fix the issue.. I have to make a signal to the main thread, to execute a function, how to do it then?

      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Loc888 said in Main thread call from another thread:

      I have to make a signal to the main thread, to execute a function, how to do it then?

      Well, you create a slot in a class living in main thread, you create a signal in a class living in the other thread, you connect these signal/slot, you emit the signal in the other thread whenever you need to notify the main thread...

      If this is not clear then please provide more information.

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

      1 Reply Last reply
      3
      • L Offline
        L Offline
        Loc888
        wrote on last edited by
        #3

        First of all, thise threads don't want to be terminated, even when i call terminate and then wait... What is the cause of that? Exit or quit don't work as well.

        jsulmJ 1 Reply Last reply
        0
        • L Loc888

          First of all, thise threads don't want to be terminated, even when i call terminate and then wait... What is the cause of that? Exit or quit don't work as well.

          jsulmJ Online
          jsulmJ Online
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Loc888 said in Main thread call from another thread:

          What is the cause of that?

          I have no idea - you did not post any code.
          You should implement thread termination properly, see https://doc.qt.io/qt-5/qthread.html#requestInterruption and https://doc.qt.io/qt-5/qthread.html#isInterruptionRequested

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

          1 Reply Last reply
          1
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            What are you using from OpenCV's highgui module ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            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