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. logmessage from another thread to the mainwindow slot

logmessage from another thread to the mainwindow slot

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 558 Views 2 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.
  • S Offline
    S Offline
    Sunfluxgames
    wrote on last edited by
    #1

    i have two classes that im trying to log a message to a textbrowser

    1. The main thread works
    2. But if i call the slot and try to emit the singal it does work.
    3. is there a way to debug it
    MainWindow::MainWindow(QWidget *parent)
        : QWidget(parent)
        , ui(new Ui::MainWindow)
        , m_window2(new Editor(this))
    , m_window3(new T_Editor(this))
    {
        ui->setupUi(this);
        connect(m_window2, & Editor::logMessage, this, &MainWindow::logMessage);
    // new thread editor 
    connect(m_window3, & T_Editor::logMessage, this, &MainWindow::logMessage);
    }
    

    If i try to emit logmessage from the other thread it doesnt work. But if i emit from editor class it works. (both in the same thread)

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      In Qt, whether signal-slot connection crosses a thread boundary or not does not matter - it works same regardless of threads. The only thing which might not work is when custom objects are sent - but then all that is needed is to properly register them. Qt warns about it at compile time - so it's not a problem in this case.

      • are you sure the signal logMessage is emitted?
      • if you are using a worker object, are you sure it emits the signal and that you connect to that signal, and not the encompassing thread?
      • are you moving m_window3 to another thread after calling connect()? In that case, it may not work
      • does it work when you hard-code connection type to Qt::QueuedConnection?
      • is your main window performing some CPU-intensive task, like a long loop or something?

      (Z(:^

      1 Reply Last reply
      1
      • S Offline
        S Offline
        Sunfluxgames
        wrote on last edited by
        #3

        m_window3 to another thread after calling connect()? In that case, it may not work.

        belive this is what it is.

        mainwindow logMessage is a private member but guess i will have to make it public to access it from the other thread object

        create a connect in the T_editor class that connects the signal logmessage with slot of mainwindow slot.

        Editor/mainwindow both run on the same thread
        Editor create a thread for T_editor that creates its own object etc..

        1 Reply Last reply
        0
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Sunfluxgames said in logmessage from another thread to the mainwindow slot:

          m_window3(new T_Editor(this))

          I don't think this object (m_window3) lives in another thread at all...

          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
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            If you want to log from different threads. You should rather have a dedicated object for that with proper protections in place.

            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
            1

            • Login

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