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. If i invoke QMetaObject::invokeMethod from thread to singletone is the invokation is still in that thread?
Forum Updated to NodeBB v4.3 + New Features

If i invoke QMetaObject::invokeMethod from thread to singletone is the invokation is still in that thread?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 3.3k 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.
  • U Offline
    U Offline
    umen242
    wrote on last edited by
    #1

    Hi
    i have thread (working great ) that invoking method in singletone object like this:

    @bool bInvokeUpdate= QMetaObject::invokeMethod(ApiManager::getInstance(),
    "updateMainWindowTree",
    Qt::BlockingQueuedConnection,
    Q_RETURN_ARG(bool, bReturnUpdate));@

    im using Qt::BlockingQueuedConnection so i can continue the thread work based on bool value .. any way
    my question is dose this invocation remains in the thread ? or it cause to method to be preformed in the main thread ?

    quick update ...
    when i debug the app when im in the thread i see in the debugger that im in thread id xxxx
    but when i set breakpoint in the updateMainWindowTree method , i see it jumping to the mainthread .
    so what does it mean that i keep invoking functions from the main thread ? how can i avoid it?

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      The code runs in the thread the singleton belongs to, which is either the thread it was created (most probably the main thread) or moved to (using QObject::moveToThread()).

      As judging from your method name <code>updateMainWindowTree</code> one should mention that you cannot do any GUI related operations outside the main thread. This includes updating any widgets.

      1 Reply Last reply
      0
      • U Offline
        U Offline
        umen242
        wrote on last edited by
        #3

        what about if i "emit" SIGNAL from Thread to GUI main thread ?
        what is better to use "emit" or QMetaObject::invokeMethod
        to update GUI , yes i know is abit different question .

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lgeyer
          wrote on last edited by
          #4

          You can of course trigger the update from another thread, provided that the update itself runs in the main thread.

          There is no difference between emit and QMetaObject::invokeMethod(), besides that emit invokes all connected methods whereas QMetaObject::invokeMethod() invokes just a single method.

          1 Reply Last reply
          0
          • L Offline
            L Offline
            LangstoniusRex
            wrote on last edited by
            #5

            Thanks for the insight! Im current trying to figure out why my app goes boom (newbie programmer) and I did not realize that about QMetaObject::InvokeMethod.

            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