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. i cannot check my QPushbutton that is in my qtableview
QtWS25 Last Chance

i cannot check my QPushbutton that is in my qtableview

Scheduled Pinned Locked Moved Unsolved General and Desktop
32 Posts 3 Posters 3.7k Views
  • 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
    aftalib
    wrote on last edited by
    #1

    Hello, i'm working on a interface using a Qtableview and i put a QPushButton in a QTableView using this :
    QPushButton* H11 = new QPushButton("H1");
    index = m_table_space_pos->index(1,1,QModelIndex());
    ui->tablespacepos->setIndexWidget(index, H11);
    ui->H11->setCheckable(true);
    connect(ui->H11,SIGNAL(clicked()),this,SLOT(on_H11_clicked()));

    the connect is supposed to change the text of the button. the thing is when i click on it nothing happens. thanks to the outputs i made i know that my button IS Checkable, but it doesnt change to true when i click on it. any ideas of where this comes from ?

    thank you in advance.

    JonBJ 1 Reply Last reply
    0
    • A aftalib

      Hello, i'm working on a interface using a Qtableview and i put a QPushButton in a QTableView using this :
      QPushButton* H11 = new QPushButton("H1");
      index = m_table_space_pos->index(1,1,QModelIndex());
      ui->tablespacepos->setIndexWidget(index, H11);
      ui->H11->setCheckable(true);
      connect(ui->H11,SIGNAL(clicked()),this,SLOT(on_H11_clicked()));

      the connect is supposed to change the text of the button. the thing is when i click on it nothing happens. thanks to the outputs i made i know that my button IS Checkable, but it doesnt change to true when i click on it. any ideas of where this comes from ?

      thank you in advance.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @aftalib said in i cannot check my QPushbutton that is in my qtableview:

      QPushButton* H11 = new QPushButton("H1");
      ui->H11->setCheckable(true);
      

      H11 is a local variable. ui->H11 is something else. How are they the same button?

      A 1 Reply Last reply
      6
      • JonBJ JonB

        @aftalib said in i cannot check my QPushbutton that is in my qtableview:

        QPushButton* H11 = new QPushButton("H1");
        ui->H11->setCheckable(true);
        

        H11 is a local variable. ui->H11 is something else. How are they the same button?

        A Offline
        A Offline
        aftalib
        wrote on last edited by
        #3

        @JonB oh wow thank you, i didnt realize this. i indeed had a button that was also named H11 in my interface and that's why it was misleading.

        so now that i have changed ui->H11 to H11 in my code i see that my button is being checked but the code in the connect does not run

        jsulmJ JonBJ 2 Replies Last reply
        0
        • A aftalib

          @JonB oh wow thank you, i didnt realize this. i indeed had a button that was also named H11 in my interface and that's why it was misleading.

          so now that i have changed ui->H11 to H11 in my code i see that my button is being checked but the code in the connect does not run

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @aftalib said in i cannot check my QPushbutton that is in my qtableview:

          but the code in the connect does not run

          Use the new Qt5 connect syntax (without SGINAL/SLOT macros) to make sure the connect actually succeeded.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • A aftalib

            @JonB oh wow thank you, i didnt realize this. i indeed had a button that was also named H11 in my interface and that's why it was misleading.

            so now that i have changed ui->H11 to H11 in my code i see that my button is being checked but the code in the connect does not run

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @aftalib
            Show your code now.

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

              here's the code of my connect : 5a3e3da9-fcf0-46ac-a75d-60ec2c01f439-image.png

              @jsulm , this doesnt seem to work : Qt says that clicked() is an undeclared identifier when i take off SIGNAL/SLOT

              my code now runs but only with the last button of the row.i suppose it's because the connect keeps assigning to the next button as the loop goes forward. is there a way to assign the connect() to each button on the loop ?

              JonBJ 1 Reply Last reply
              0
              • A aftalib

                here's the code of my connect : 5a3e3da9-fcf0-46ac-a75d-60ec2c01f439-image.png

                @jsulm , this doesnt seem to work : Qt says that clicked() is an undeclared identifier when i take off SIGNAL/SLOT

                my code now runs but only with the last button of the row.i suppose it's because the connect keeps assigning to the next button as the loop goes forward. is there a way to assign the connect() to each button on the loop ?

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #7

                @aftalib said in i cannot check my QPushbutton that is in my qtableview:

                Qt says that clicked() is an undeclared identifier when i take off SIGNAL/SLOT

                You have to read and act on https://wiki.qt.io/New_Signal_Slot_Syntax.

                here's the code of my connect

                You show no connect() statement. You show your proposed slot code instead.

                A 1 Reply Last reply
                1
                • JonBJ JonB

                  @aftalib said in i cannot check my QPushbutton that is in my qtableview:

                  Qt says that clicked() is an undeclared identifier when i take off SIGNAL/SLOT

                  You have to read and act on https://wiki.qt.io/New_Signal_Slot_Syntax.

                  here's the code of my connect

                  You show no connect() statement. You show your proposed slot code instead.

                  A Offline
                  A Offline
                  aftalib
                  wrote on last edited by
                  #8

                  @JonB sorry, here's my connect() : d21ee820-b557-4b71-84f2-49c37338c200-image.png

                  thank you, i'm going to read this

                  JonBJ 1 Reply Last reply
                  0
                  • A aftalib

                    @JonB sorry, here's my connect() : d21ee820-b557-4b71-84f2-49c37338c200-image.png

                    thank you, i'm going to read this

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #9

                    @aftalib
                    Earlier I only see:

                    index = m_table_space_pos->index(1,1,QModelIndex());
                    

                    I do not see where you are creating QPushButtons in a loop, putting each one into the table, and connecting each one to the slot. I see you only addressing (1, 1) in the table.

                    Further, the slot only looks at one H11 variable. I do not know how that H11 relates to each of the push buttons you created.

                    If you seem to intend AntArrayDialog::on_H11_clicked() slot to handle any of the buttons pressed (connect()ed to each one), it is going to need to know which button was clicked. And that will require you to use a C++ lambda for the connection, to pass which button was clicked as a parameter to the slot....

                    Start by just verifying your slot gets called for any button clicked, not just one button....

                    A 1 Reply Last reply
                    1
                    • JonBJ JonB

                      @aftalib
                      Earlier I only see:

                      index = m_table_space_pos->index(1,1,QModelIndex());
                      

                      I do not see where you are creating QPushButtons in a loop, putting each one into the table, and connecting each one to the slot. I see you only addressing (1, 1) in the table.

                      Further, the slot only looks at one H11 variable. I do not know how that H11 relates to each of the push buttons you created.

                      If you seem to intend AntArrayDialog::on_H11_clicked() slot to handle any of the buttons pressed (connect()ed to each one), it is going to need to know which button was clicked. And that will require you to use a C++ lambda for the connection, to pass which button was clicked as a parameter to the slot....

                      Start by just verifying your slot gets called for any button clicked, not just one button....

                      A Offline
                      A Offline
                      aftalib
                      wrote on last edited by aftalib
                      #10

                      @JonB my bad i hadnt updated my code at the time because i was doing tests to see if it was working for one button but i replaced (1,1) with (1,i) so i indeed have a row of buttons.
                      my slot gets called for the last button that is in the row of my TableView

                      i'm going to see about the C++ lambda you're talking about, it might be the solution i was looking for

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        aftalib
                        wrote on last edited by
                        #11

                        so C++ lambda might be the way to relate to each of the QPushButtons i created with my loop ?

                        JonBJ 1 Reply Last reply
                        0
                        • A aftalib

                          so C++ lambda might be the way to relate to each of the QPushButtons i created with my loop ?

                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by JonB
                          #12

                          @aftalib
                          You will need the lambda when you are ready to have the single slot code method handle the clicking of any of the push buttons, which I suspect is what you will want to achieve.

                          However, before you do that, put a qDebug() << "clicked" in as the first statement in the slot. Verify that gets called when any of the buttons you created are clicked, not just one button. Only at that point are you ready to move to a lambda for the slot which will pass which button was pressed as a parameter to the slot....

                          A 1 Reply Last reply
                          1
                          • JonBJ JonB

                            @aftalib
                            You will need the lambda when you are ready to have the single slot code method handle the clicking of any of the push buttons, which I suspect is what you will want to achieve.

                            However, before you do that, put a qDebug() << "clicked" in as the first statement in the slot. Verify that gets called when any of the buttons you created are clicked, not just one button. Only at that point are you ready to move to a lambda for the slot which will pass which button was pressed as a parameter to the slot....

                            A Offline
                            A Offline
                            aftalib
                            wrote on last edited by aftalib
                            #13

                            @JonB okay, the slot gets called of any of the buttons i have created, i have the "clicked" output on each of the buttons

                            JonBJ 1 Reply Last reply
                            0
                            • A aftalib

                              @JonB okay, the slot gets called of any of the buttons i have created, i have the "clicked" output on each of the buttons

                              JonBJ Offline
                              JonBJ Offline
                              JonB
                              wrote on last edited by JonB
                              #14

                              @aftalib
                              And have you used the new style syntax I referred you to earlier? Show your connect() statement now.

                              A 1 Reply Last reply
                              0
                              • JonBJ JonB

                                @aftalib
                                And have you used the new style syntax I referred you to earlier? Show your connect() statement now.

                                A Offline
                                A Offline
                                aftalib
                                wrote on last edited by
                                #15

                                @JonB i dont think i got it right.. the IDE still says that clicked() is an undeclared identifier.. 5d0c7d30-3cdf-4f64-a2c0-8429bc0d725f-image.png

                                JonBJ jsulmJ 2 Replies Last reply
                                0
                                • A aftalib

                                  @JonB i dont think i got it right.. the IDE still says that clicked() is an undeclared identifier.. 5d0c7d30-3cdf-4f64-a2c0-8429bc0d725f-image.png

                                  JonBJ Offline
                                  JonBJ Offline
                                  JonB
                                  wrote on last edited by
                                  #16

                                  @aftalib
                                  I said to you earlier:

                                  You have to read and act on https://wiki.qt.io/New_Signal_Slot_Syntax.

                                  but you do not seem to have done anything about this....

                                  A 1 Reply Last reply
                                  1
                                  • JonBJ JonB

                                    @aftalib
                                    I said to you earlier:

                                    You have to read and act on https://wiki.qt.io/New_Signal_Slot_Syntax.

                                    but you do not seem to have done anything about this....

                                    A Offline
                                    A Offline
                                    aftalib
                                    wrote on last edited by
                                    #17

                                    @JonB no i did check this in order to do the new connect statement but i dont get how am i supposed to write this with what is written on this page

                                    JonBJ 1 Reply Last reply
                                    0
                                    • A aftalib

                                      @JonB i dont think i got it right.. the IDE still says that clicked() is an undeclared identifier.. 5d0c7d30-3cdf-4f64-a2c0-8429bc0d725f-image.png

                                      jsulmJ Offline
                                      jsulmJ Offline
                                      jsulm
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #18

                                      @aftalib Please post text not screen shots.

                                      connect(H11, &QPushButton::clicked, this, &WHAT_EVER_THIS_TYPE_IS::on_H11_clicked);
                                      

                                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                                      1 Reply Last reply
                                      3
                                      • A aftalib

                                        @JonB no i did check this in order to do the new connect statement but i dont get how am i supposed to write this with what is written on this page

                                        JonBJ Offline
                                        JonBJ Offline
                                        JonB
                                        wrote on last edited by JonB
                                        #19

                                        @aftalib
                                        The very first section there shows an example of changing from SIGNAL/SLOT() macros

                                        connect(
                                            sender, SIGNAL( valueChanged( QString, QString ) ),
                                            receiver, SLOT( updateValue( QString ) )
                                        );
                                        

                                        over to

                                        connect(
                                            sender, &Sender::valueChanged,
                                            receiver, &Receiver::updateValue
                                        );
                                        

                                        The code you have pasted does not attempt to follow that required pattern.

                                        1 Reply Last reply
                                        1
                                        • A Offline
                                          A Offline
                                          aftalib
                                          wrote on last edited by
                                          #20

                                          okay thats my bad i didnt quite understand the syntax that was written in the new connect statement but i think i got it now, thank you. here's what i wrote :

                                                   connect(H11, &QPushButton::clicked,this,&AntArrayDialog::on_H11_clicked);
                                          
                                          

                                          i dont get any errors and the program launches well

                                          JonBJ 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