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. Signal/Slot clarification [SOLVED]

Signal/Slot clarification [SOLVED]

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

    Is the signal/slot pair working like a callback mechanism? If I want to create a custom pair signal/slot can I pass as parameter every kind of object? Is this wrong?

    thanks in advance

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      Hi there,
      Any type of parameter within the C++ library is possible. Even user defined structures etc. It is just a special way to call (member) functions automatically when a event occurs. So any class can create a signal an can be paired to a slot.
      Might be a good suggestion to read the signal/slot information before venturing into this part of coding. Isn't all that difficult to understand.
      "http://doc.qt.nokia.com/4.7-snapshot/signalsandslots.html"
      Greetz

      Greetz, Jeroen

      1 Reply Last reply
      0
      • B Offline
        B Offline
        blackbelt
        wrote on last edited by
        #3

        thank you for the answer. I have the following code:

        @void mySlot(const std::list<MyClass*> &);

        void
        MyManager::mySlot(const std::list<MyClass*> &theList)
        {
        std::cout << "mySlot " << std::endl;
        }

        void mySignal(const std::list<MyClass*> &theList);

        TestThread ::TestThread (std::list<MyClass*>&theList, QObject *parent)
        : QThread(parent), myList(theList)
        {

        }

        void
        TestThread ::run()
        {
        ...
        emit mySignal(myList);
        }@

        @QObject::connect(threadObj, SIGNAL(mySignal(std::list<MyClass*>)), this, SLOT(mySlot(std::list<MyClass*>)));@

        the slot is never fired. What's wrong?

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #4

          [quote author="blackbelt" date="1343654430"]Is the signal/slot pair working like a callback mechanism? If I want to create a custom pair signal/slot can I pass as parameter every kind of object? Is this wrong?

          thanks in advance[/quote]

          It's more like publisher/subscriber pattern. You can have any number of slots being connected to one signal.

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DerManu
            wrote on last edited by
            #5

            QObject::connect prints a qDebug message when signal-slot-connection fails. Do you see such a message in debug mode?
            If not: Is the connection made before emitting the signal?

            And finally: Try not to mix Qt and STL when not absolutely necessary. For example, use QList or QLinkedList instead of std::list.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              Signal-slot connections between threads have some more restrictions than the normal, direct ones. That is because the mechanism needs to be able to serialize and deserialize the data. I note from your code that you seem to be using multiple threads.

              Did you register your type to the [[doc:QMetaType]] system?

              1 Reply Last reply
              0
              • B Offline
                B Offline
                blackbelt
                wrote on last edited by
                #7

                Yes, register the QMetaType did the trick . Thank you

                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