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. Problem connecting Signals and Slots in a modal dialog
Forum Updated to NodeBB v4.3 + New Features

Problem connecting Signals and Slots in a modal dialog

Scheduled Pinned Locked Moved Solved General and Desktop
18 Posts 3 Posters 1.7k 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.
  • mrjjM mrjj

    @eschmo
    Hi
    So now the right dialog show up but pressing your ui->Btn_Save_Settings
    does nothing ?

    E Offline
    E Offline
    eschmo
    wrote on last edited by
    #7

    @mrjj

    Yes exactely, bu it was the right Dialog all the time but obviously just the appearance not the code.
    I've also switched to the new connection syntax but debug shows true for the old way as well.

        qDebug() << "Tab Connect:" <<connect(ui->tabWidget,&QTabWidget::currentChanged,this,&H17T_Settings::onTabChanged);
        qDebug() << "Button Connect:" <<connect(ui->Btn_Save_Settings,&QPushButton::clicked,this,&H17T_Settings::close);
    
    Tab Connect: true
    Button Connect: true
    
    mrjjM J.HilkJ 2 Replies Last reply
    0
    • E eschmo

      @mrjj

      Yes exactely, bu it was the right Dialog all the time but obviously just the appearance not the code.
      I've also switched to the new connection syntax but debug shows true for the old way as well.

          qDebug() << "Tab Connect:" <<connect(ui->tabWidget,&QTabWidget::currentChanged,this,&H17T_Settings::onTabChanged);
          qDebug() << "Button Connect:" <<connect(ui->Btn_Save_Settings,&QPushButton::clicked,this,&H17T_Settings::close);
      
      Tab Connect: true
      Button Connect: true
      
      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #8

      @eschmo
      Hi
      Super with the new syntax as then, we are very sure it's not the connect.

      Try replace the close() with accept();
      and see if it then closes.

      btw does Settings::onTabChange gets called ?

      If not I think its something else.

      E 1 Reply Last reply
      0
      • mrjjM mrjj

        @eschmo
        Hi
        Super with the new syntax as then, we are very sure it's not the connect.

        Try replace the close() with accept();
        and see if it then closes.

        btw does Settings::onTabChange gets called ?

        If not I think its something else.

        E Offline
        E Offline
        eschmo
        wrote on last edited by
        #9

        @mrjj

        no, nothing is called at all.

        I've redone the connection for the "Save Button" with the designer and it worked straight afterwards.
        I did it again in the cpp and it doesnt work. thats quite irritating.

        mrjjM 1 Reply Last reply
        0
        • E eschmo

          @mrjj

          no, nothing is called at all.

          I've redone the connection for the "Save Button" with the designer and it worked straight afterwards.
          I did it again in the cpp and it doesnt work. thats quite irritating.

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

          @eschmo
          That is very odd.

          You only create a H17T_Settings once place right ?

          and if it works assigning a slot in Designer for the same dialog then it must work too
          with manual connect as its much the same.

          Just to be sure. You go to Designer and use the "go to slot" function to create a slot
          for it and there you call close()

          but if you don't do this and just have the manual connects it wont work ?

          E 1 Reply Last reply
          0
          • mrjjM mrjj

            @eschmo
            That is very odd.

            You only create a H17T_Settings once place right ?

            and if it works assigning a slot in Designer for the same dialog then it must work too
            with manual connect as its much the same.

            Just to be sure. You go to Designer and use the "go to slot" function to create a slot
            for it and there you call close()

            but if you don't do this and just have the manual connects it wont work ?

            E Offline
            E Offline
            eschmo
            wrote on last edited by
            #11

            @mrjj

            yes exactely, i'Ve even put the connection for tabwidget currentChange() in the ui file by hand and it works with H17T_Settings close().

            But it will not work in anyway with my connections over the cpp, even if they succeed to connect.

            Thats quite strange...

            mrjjM 1 Reply Last reply
            0
            • E eschmo

              @mrjj

              yes exactely, i'Ve even put the connection for tabwidget currentChange() in the ui file by hand and it works with H17T_Settings close().

              But it will not work in anyway with my connections over the cpp, even if they succeed to connect.

              Thats quite strange...

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

              @eschmo

              Yes its very strange as it should work when connect returns true and besides with the
              new syntax, the compiler would tell if something fishy.

              All seems fine with H17T_Settings soI cant I guess why onTabChanged() is not called.

              1 Reply Last reply
              0
              • E eschmo

                @mrjj

                Yes exactely, bu it was the right Dialog all the time but obviously just the appearance not the code.
                I've also switched to the new connection syntax but debug shows true for the old way as well.

                    qDebug() << "Tab Connect:" <<connect(ui->tabWidget,&QTabWidget::currentChanged,this,&H17T_Settings::onTabChanged);
                    qDebug() << "Button Connect:" <<connect(ui->Btn_Save_Settings,&QPushButton::clicked,this,&H17T_Settings::close);
                
                Tab Connect: true
                Button Connect: true
                
                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by mrjj
                #13

                @eschmo said in Problem connecting Signals and Slots in a modal dialog:

                Yes exactely, bu it was the right Dialog all the time but obviously just the appearance not the code.
                I've also switched to the new connection syntax but debug shows true for the old way as well.

                No it was not, It could not have been the correct dialog, when you instantiated a different dialog.

                I think you have simply multiple dialogs instances ore something along that line.

                can you post/link a minimal compellable example?


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                E 1 Reply Last reply
                1
                • J.HilkJ J.Hilk

                  @eschmo said in Problem connecting Signals and Slots in a modal dialog:

                  Yes exactely, bu it was the right Dialog all the time but obviously just the appearance not the code.
                  I've also switched to the new connection syntax but debug shows true for the old way as well.

                  No it was not, It could not have been the correct dialog, when you instantiated a different dialog.

                  I think you have simply multiple dialogs instances ore something along that line.

                  can you post/link a minimal compellable example?

                  E Offline
                  E Offline
                  eschmo
                  wrote on last edited by
                  #14

                  @mrjj
                  yes i'm a little bit confused and lost about it.
                  anyway, thanks a lot for your help.

                  @J-Hilk

                  it has appeared exactly as the dialog i've prepared in the designer.
                  Thats for sure because of

                  frm_Settings.setupUi(SettingsForm);
                  

                  and fits why not my overloaded constructor is in place but the standart one of QDialog.

                  I couldnt find any other instance in my code, but i dont see how this could affect the called dialog.

                  I've put the whole project to github if this could help.

                  https://github.com/eschmo/H17-Timing/tree/main/H17-Timing

                  Thanks a lot for your time!

                  J.HilkJ 1 Reply Last reply
                  2
                  • E eschmo

                    @mrjj
                    yes i'm a little bit confused and lost about it.
                    anyway, thanks a lot for your help.

                    @J-Hilk

                    it has appeared exactly as the dialog i've prepared in the designer.
                    Thats for sure because of

                    frm_Settings.setupUi(SettingsForm);
                    

                    and fits why not my overloaded constructor is in place but the standart one of QDialog.

                    I couldnt find any other instance in my code, but i dont see how this could affect the called dialog.

                    I've put the whole project to github if this could help.

                    https://github.com/eschmo/H17-Timing/tree/main/H17-Timing

                    Thanks a lot for your time!

                    J.HilkJ Offline
                    J.HilkJ Offline
                    J.Hilk
                    Moderators
                    wrote on last edited by J.Hilk
                    #15

                    @eschmo
                    inside your h17t_main.h
                    your SettingsForm member pointer is this:

                    QDialog *SettingsForm
                    

                    and it should be:

                    H17T_Settings *SettingsForm;
                    

                    That should fix your issue, but from looking at the rest of your code:

                    • You're going to leak memory with H17T_Settings instances.
                    • You're set up to do threading stuff that apparently have access to GUI stuff

                    Both are a big nono... :D


                    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                    Q: What's that?
                    A: It's blue light.
                    Q: What does it do?
                    A: It turns blue.

                    E 1 Reply Last reply
                    3
                    • mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by mrjj
                      #16

                      Hi
                      Also a note

                      You do

                      void H17T_Main::onSettings()
                      {
                          SettingsForm = new H17T_Settings; // this also calls setupUI
                      ...
                          frm_Settings.setupUi(SettingsForm); <<< what is this for ? now you create all
                           the widgets once more so the other ones that was connected in the constructor is no longer 
                          the ones shown on screen. This should not be needed to call manually.
                          SettingsForm->show();
                      }
                      
                      

                      That seems to be the reason as it works without that line :)
                      alt text

                      1 Reply Last reply
                      3
                      • J.HilkJ J.Hilk

                        @eschmo
                        inside your h17t_main.h
                        your SettingsForm member pointer is this:

                        QDialog *SettingsForm
                        

                        and it should be:

                        H17T_Settings *SettingsForm;
                        

                        That should fix your issue, but from looking at the rest of your code:

                        • You're going to leak memory with H17T_Settings instances.
                        • You're set up to do threading stuff that apparently have access to GUI stuff

                        Both are a big nono... :D

                        E Offline
                        E Offline
                        eschmo
                        wrote on last edited by
                        #17

                        @J-Hilk said in Problem connecting Signals and Slots in a modal dialog:

                        QDialog

                        Sorry, not sure why this was in the files i've uploaded but this was allready changed yesterday.

                        Finally thanks a lot, because the solution was your second tip.

                        I've removed it completely and everything is fine now!

                        Thanks a lot to both of you!!

                        J.HilkJ 1 Reply Last reply
                        2
                        • E eschmo

                          @J-Hilk said in Problem connecting Signals and Slots in a modal dialog:

                          QDialog

                          Sorry, not sure why this was in the files i've uploaded but this was allready changed yesterday.

                          Finally thanks a lot, because the solution was your second tip.

                          I've removed it completely and everything is fine now!

                          Thanks a lot to both of you!!

                          J.HilkJ Offline
                          J.HilkJ Offline
                          J.Hilk
                          Moderators
                          wrote on last edited by
                          #18

                          @eschmo said in Problem connecting Signals and Slots in a modal dialog:

                          I've removed it completely and everything is fine now!

                          I'm afraid that credit goes to @mrjj ;)

                          Sorry, not sure why this was in the files i've uploaded but this was allready changed yesterday.

                          I'm talking header, not cpp
                          d87a69c8-6117-4c3b-9fe0-b70c5734e36a-image.png


                          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                          Q: What's that?
                          A: It's blue light.
                          Q: What does it do?
                          A: It turns blue.

                          1 Reply Last reply
                          1

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved