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. Slot gets not invoked
Forum Updated to NodeBB v4.3 + New Features

Slot gets not invoked

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 626 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.
  • M Offline
    M Offline
    makopo
    wrote on last edited by makopo
    #1

    Hi,

    I had thought, I understand signals and slots, but there is a problem I did not get solved. I would like to give a short overview:
    I have three classes. In the constructor of ReceiveData I implement two connect functions which send data from worker to a slot:

    ReceiveData::ReceiveData(QWidget* parent)  
    {
        QObject::connect(m_worker, &Worker::SendData, this, &ReceiveData::PublishData, Qt::QueuedConnection);
        QObject::connect(m_worker, &Worker::SendData, m_convertData, &Converter::ConvertData, Qt::QueuedConnection);
    }
    

    Calling slots in these class works. ReceiveData is derived from QWidget.

    I have another worker class, named Converter. Here I implement a slot thats converts my data. This slot also emits a signal that sends the converted data to a slot in another class, named StoreData. The class Converter is derived from QObject.

    void Converter::ConvertData(Datatype* data) {
        //... Converting stuff ...
        emit SendConvertedData(m_convertedData);
    }
    

    Than the third class StoreData implements the connect function like this and is also derived from QWidget:

    QObject::connect(m_converter, &Converter::SendConvertedData, this, &StoreData::CopyData, Qt::DirectConnection);
    

    So the converted data is send to a slot which copied the data. And here is the problem, because in the class StoreData the call of CopyData did not work. But when I move the last connect function to the class ReceiveData the slot CopyData gets invoked.
    All classes runs in the same thread, so I did not understand why there is a problem.

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

      QObject::connect(m_converter,...

      Are you sure this instance really emits the signal and not another one?

      All classes runs in the same thread,

      Why the QueuedConnection and DirectConnection then? Not needed...

      ConvertData(T* data)

      Template class? How did you solve the problem with Q_OBJECT macro there?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

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

        Hi,

        In addition to @Christian-Ehrlicher, is
        @makopo said in Slot gets not invoked:

        m_worker

        properly initialized ?

        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
        • Christian EhrlicherC Christian Ehrlicher

          QObject::connect(m_converter,...

          Are you sure this instance really emits the signal and not another one?

          All classes runs in the same thread,

          Why the QueuedConnection and DirectConnection then? Not needed...

          ConvertData(T* data)

          Template class? How did you solve the problem with Q_OBJECT macro there?

          M Offline
          M Offline
          makopo
          wrote on last edited by makopo
          #4

          @Christian-Ehrlicher said in Slot gets not invoked:

          Are you sure this instance really emits the signal and not another one?
          Why the QueuedConnection and DirectConnection then? Not needed.

          ReceiveData, ConvertData and StoreData runs in the same thread, in detail in the main thread. The class Worker that send the raw data runs ins an seperate thread.

          Template class? How did you solve the problem with Q_OBJECT macro there?

          No template class. I wrote T to mark any data type.

          @SGaist said in Slot gets not invoked:

          m_worker

          properly initialized ?

          m_worker is initialized. I add qDebug to the slots PublishData and ConvertData and can see that this connection works.
          There is only a problem with this connection:

          QObject::connect(m_converter, &Converter::SendConvertedData, this, &StoreData::CopyData, Qt::DirectConnection);
          

          that runs in the class ReceiveData but not in in the StoreData class.
          m_converter is also initialized. Setting the connection type to Qt::Autoconnection does not show a positive result.

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

            @makopo said in Slot gets not invoked:

            m_converter is also initialized.

            This was not the question - the question was if this is really the object where you do the emit or if there is another one around. Please add a debug statement to print out the address of m_converter there and this where you do the emit to check if they're the same. I would guess they're not.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            M 2 Replies Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              @makopo said in Slot gets not invoked:

              m_converter is also initialized.

              This was not the question - the question was if this is really the object where you do the emit or if there is another one around. Please add a debug statement to print out the address of m_converter there and this where you do the emit to check if they're the same. I would guess they're not.

              M Offline
              M Offline
              makopo
              wrote on last edited by
              #6

              @Christian-Ehrlicher
              Thanks for the advice. I will check this in the afternoon.

              1 Reply Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher

                @makopo said in Slot gets not invoked:

                m_converter is also initialized.

                This was not the question - the question was if this is really the object where you do the emit or if there is another one around. Please add a debug statement to print out the address of m_converter there and this where you do the emit to check if they're the same. I would guess they're not.

                M Offline
                M Offline
                makopo
                wrote on last edited by
                #7

                Problem solved. Thanks for your advices!

                SGaistS 1 Reply Last reply
                0
                • M makopo

                  Problem solved. Thanks for your advices!

                  SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @makopo What was the issue ?

                  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