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 slots question
Qt 6.11 is out! See what's new in the release blog

Signal slots question

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

    hi everybody . i have one question

    @
    #include <QtGui>

    void slt()
    {
    // do something
    }

    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);

    QPushButton btn;
    
    // connect btn signal(clicked()) to slt "function" !! i want connect to function not object!
    
    return app.exec();
    

    }
    @

    tnx for your help :)

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Flurite
      wrote on last edited by
      #2

      You must have a class that contains your slot, which is in this case, void slot(). Have you defined your class somewhere? If so, can we see it?

      I'm no expert on this, but I think I may be able to help you here..

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dbzhang800
        wrote on last edited by
        #3

        What you need is some basic knowledge of Qt. And this will be useful for you www.catb.org/~esr/faqs/smart-questions.html


        What you provided are some Qt4's code snippets, but your slt() is not a Qt SLOT at all!

        However, you can do similar thing with Qt5 using the new SIGNAL & SLOT syntax.

        Read the manual carefully.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          ahura_24
          wrote on last edited by
          #4

          if i have too many button or .... and i want define for them different slots , what i must to do ? i must declare to many class or one global class !! if i have too many button and for each of them has been one slot , how can i declare this ?!!

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

            I think what you need is to:

            learn better English

            get some more practice in object oriented programming

            rethink and rephrase your questions so that other people - who want to help you - can understand them clearly

            read Qt documentation on "signal and slot mechanism":http://qt-project.org/doc/qt-4.8/signalsandslots.html, it's really well written.

            The answer to your questions, as far as I can get what you mean, is this: you can declare multiple slots in a single class, and connect your button signals to them (that is more or less the standard practice), or create one slot and handle all signals there (this is ugly, I won't recommend).

            About "how can I declare this"... really, really, DO read the docs. Here is a snippet:
            @
            public slots:
            void mySlot();
            @

            And in source somewhere:
            @
            connect(someButton, SIGNAL(clicked()), someObject, SLOT(mySlot()));

            .....

            void MyClass::mySlot() {
            /// code
            }

            @

            (Z(:^

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

              You can define one ore more classes with one or more slots.
              signals of an object in Qt 4.x MUST be connected to a slot of an object. Whether you use one or more classes for the slots is up to you.

              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
              • sierdzioS Offline
                sierdzioS Offline
                sierdzio
                Moderators
                wrote on last edited by
                #7

                Damn, I do sound quite arrogant at times :( Sorry.

                But I really mean it with reading the documentation.

                (Z(:^

                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