Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    Unsolved Help with setting basic Signal and Slot

    General and Desktop
    2
    8
    1237
    Loading More Posts
    • 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.
    • HashDragon
      HashDragon last edited by HashDragon

      Hello everyone.
      I have a QButtonGroup of radioButtons and I want that upon clicking of a certain radioButton(with ID say x), it should execute a function of another class(form) till the time radioButton selection does not change. I am fairly new to QT and have been trying to implement this since a long time but in vain.
      Right now, here is my relevant piece of code :

      switch(ui->buttonGroup->checkedId())
                  {
                     case -3 : //do something
                     break;
                     case x: //call that function from another class
                     break;
                 }
      

      But I think this switch statement won't be required If I am able to establish a signal/slot connection. Its too confusing. Any help would be appreciated. Thanks!

      1 Reply Last reply Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        @HashDragon said:

        execute a function of another class(form) till the time radioButton selection does not change

        what does this means ?
        If I select RadioButt 4. for example, it should
        keep calling the same function until i select another RB?

        HashDragon 1 Reply Last reply Reply Quote 0
        • HashDragon
          HashDragon @mrjj last edited by

          @mrjj yes precisely

          mrjj 1 Reply Last reply Reply Quote 0
          • mrjj
            mrjj Lifetime Qt Champion @HashDragon last edited by mrjj

            @HashDragon
            Well the basic of signal and slots is that when something
            happens a signal is sent and and some reacts.
            So only 1 signal is sent when u select that RB, so u need more code.

            You can use a Qtimer.
            and start it when X RB is selected.

            This timer sends a signal timeout() on each seconds/what you set.
            So in this slot you can then call the function you need.

            If a new RB is selected u stop the timer again.

            so something like
            (in mainwin constructor, NOT in your function)

            QTimer *timer = new QTimer(this);
            connect(timer, SIGNAL(timeout()), this, SLOT(TimerTick()));
            

            then in mainwin.h
            private slots:
            void TimerTick();

            and in mainwin.cpp

            void MainWindow::TimerTick()
            {
            callthefunc
            }

            and when right RB is clicked/checked
            timer->start(1000);
            and when other is clicked
            timer->stop();

            Note: for long lasting operations in callthefunc, a timer is not the way to do it.

            HashDragon 1 Reply Last reply Reply Quote 0
            • HashDragon
              HashDragon @mrjj last edited by HashDragon

              @mrjj This looks elegant! However, the function I need to call is a part of another form.
              How do I call it in my mainwindow ? And what is your approximation for "long lasting?"
              Thanks!

              mrjj 1 Reply Last reply Reply Quote 0
              • mrjj
                mrjj Lifetime Qt Champion @HashDragon last edited by

                @HashDragon
                well the other form, do u show this in main? it seems a bit strange to call
                its function if its not shown, but it is possible.
                A more clean design would be using signals but lets see how to call it never the less.

                so lets call form MyForm
                then you would do
                MyForm fm;
                fm.callsomefunction();
                but it wont keep window open or anything.

                so im not sure what u are trying?

                Where do u show this other form?
                There you would have a pointer to it.

                • approximation for "long lasting?"
                  well more than a few sec.

                But overall i dont understand why mainwindow would have to repeatedly call a function in another form object.
                Seems not so right :)

                HashDragon 1 Reply Last reply Reply Quote 0
                • HashDragon
                  HashDragon @mrjj last edited by

                  @mrjj Actually I am developing an OpenCV program. I have a mainwindow with a set of buttons. Say, I press on a button "Threshold", then it will open another form which has the design for Thresholding(i.e all the trackbars to vary the HSV properties,etc). So my threshold function is defined in that particular form. So I need to work on "each frame" which the camera is capturing(therefore the term "infinitely call" to threshold function).
                  I have a pointer to that form available but with that I'm not able to access the functions of that form(even though its declared as public) .

                  mrjj 1 Reply Last reply Reply Quote 0
                  • mrjj
                    mrjj Lifetime Qt Champion @HashDragon last edited by mrjj

                    @HashDragon
                    Ok i see. Never use used OpenCV so forgive any ignorance on my part.

                    • Thresholding
                      Why do u need to "drive it" from mainwindow?
                      it seems to me that the UI form Object could very well do this it self , once open ?
                      Like it open source and process it. Or does mainwindow contain feed and u need to just show
                      widgets to adjust Threshold ? is there a frame/preview in this other window?
                      --
                      button "Threshold" could call slot.
                      in that slot you

                    Thresholddialog Thresholddia;
                    Thresholddia.exec();
                    here the main/GUI thread is directed into exec() so it blocks the mainwindow.
                    Im not sure that is what you are after?

                    Do you call show() or exec() on your Thresholddialog ?

                    I have a pointer to that form available but with that I'm not able to access the functions
                    is the pointer of the correct class type`? You should be able to call methods.

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post