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. Issues connecting signal and slots[SOLVED]

Issues connecting signal and slots[SOLVED]

Scheduled Pinned Locked Moved General and Desktop
15 Posts 4 Posters 3.4k Views 3 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.
  • mrjjM mrjj

    hi
    code seems fine.
    did you check return value of

    qDebug() << "patcon" <<   connect(_patientinfo,SIGNAL(checkInputSignal()),_idnamebar,SLOT(onCheckInput()));
    

    And I assume you put a debug() too in
    dNameBar::onCheckInput()
    and it never gets in there?

    M Offline
    M Offline
    marlenet15
    wrote on last edited by
    #3

    @mrjj It said "patcon true" and when I put debug on the idNameBar nothing outputs.

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

      Hi,

      checkInput is called in patientinfo's constructor which means the signal is emitted before the connection happens.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      mrjjM M 2 Replies Last reply
      0
      • SGaistS SGaist

        Hi,

        checkInput is called in patientinfo's constructor which means the signal is emitted before the connection happens.

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #5

        @SGaist
        Ah, good spotted.

        1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          checkInput is called in patientinfo's constructor which means the signal is emitted before the connection happens.

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

          @SGaist I can't think of another way to write the code. Can you give me suggestions?

          1 Reply Last reply
          0
          • M Offline
            M Offline
            marlenet15
            wrote on last edited by
            #7

            Ok so I created the connection in patientinfo.cpp and commented out the one in mainwindow.cpp

            _idNameBar = new IdNameBar;
            .
            .
            .
            connect(this,SIGNAL(checkInputSignal()),_idNameBar,SLOT(onCheckInput()));
            checkInput();
            }
            

            and on patientinfo.h I added

            #include "idnamebar.h"
            IdNameBar *_idNameBar;
            

            I get the qdebug output as :
            checking mySig
            checking slot
            emitting slot
            emitted mySig

            the button does not disable though

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

              Now it's another subtlety: the event loop has not yet started, so it's not yet propagating.

              Anyway, the current architecture doesn't look quite right. onCheckInput just disables the next button, how do you plan to enable it again ?

              What you describes sounds a bit like QWizard, you should take a look at that class.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              M 1 Reply Last reply
              0
              • SGaistS SGaist

                Now it's another subtlety: the event loop has not yet started, so it's not yet propagating.

                Anyway, the current architecture doesn't look quite right. onCheckInput just disables the next button, how do you plan to enable it again ?

                What you describes sounds a bit like QWizard, you should take a look at that class.

                M Offline
                M Offline
                marlenet15
                wrote on last edited by
                #9

                @SGaist I really do not want to use QWizard since I don't want that exact look. I know I have to enable it again but I am doing it step by step. I just want to make the button disabled if that field is empty. Once I can make that work, I will work on enabling it again once there is something in that field which is the patient name.

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

                  Then you should rather add a signal to your patientinfo class that contains a boolean parameter to tell whether the its content is empty or not and connect that signal to your IdNameBar class. patientinfo should not have to care nor know about IdNameBar, it's not its responsibility.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  M 1 Reply Last reply
                  1
                  • SGaistS SGaist

                    Then you should rather add a signal to your patientinfo class that contains a boolean parameter to tell whether the its content is empty or not and connect that signal to your IdNameBar class. patientinfo should not have to care nor know about IdNameBar, it's not its responsibility.

                    M Offline
                    M Offline
                    marlenet15
                    wrote on last edited by
                    #11

                    @SGaist I have tried doing that but nothing happens still. The qdebug tells me i did go to the slot but the button is still enabled no matter what.

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

                      Since you don't want to disable the button at construction time (which would be logical since no validation has been done), then you must trigger the check after the event loop has started. You can use a single shot QTimer with a timeout at 0 for that.

                      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
                      • M Offline
                        M Offline
                        marlenet15
                        wrote on last edited by
                        #13

                        Ohh so you mean to disable the button at the beginning no matter what? I guess that makes sense. Ill try that!

                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          MXXIV
                          wrote on last edited by
                          #14

                          I just want to remind you that many errors can be caught if you use the new Qt Connect syntax.

                          1 Reply Last reply
                          0
                          • M Offline
                            M Offline
                            marlenet15
                            wrote on last edited by
                            #15

                            I followed this post: https://forum.qt.io/topic/4847/how-to-enable-a-submit-button-after-multiple-form-fields-have-been-verified/13
                            and now it works! 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