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. [Solved] Connect combobox using signals
Forum Updated to NodeBB v4.3 + New Features

[Solved] Connect combobox using signals

Scheduled Pinned Locked Moved General and Desktop
qcomboboxsignal
22 Posts 3 Posters 13.8k Views 2 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.
  • R Ratzz
    27 Jun 2015, 12:38

    I am a newbie to QT can you tell how to pass a parent to QComboBox / QLabel?
    I used below code Which opens the combobox and label in new window.But i want it in same mainwindow.

    combobox->show();
     label->show();
    P Offline
    P Offline
    p3c0
    Moderators
    wrote on 27 Jun 2015, 12:41 last edited by p3c0
    #11

    @Ratzz As said earlier just pass this. Thus it makes MainWindow parent of combobox and it will not open in new window. You have already done the same for pushbutton.
    Edit: Pass it in it's constructor.

    157

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Ratzz
      wrote on 27 Jun 2015, 12:43 last edited by Ratzz
      #12

      @p3c0
      thank you.
      I used this
      combobox = new QComboBox(this);
      Is it the proper way to do it ?

      --Alles ist gut.

      P 1 Reply Last reply 27 Jun 2015, 12:45
      0
      • R Ratzz
        27 Jun 2015, 12:43

        @p3c0
        thank you.
        I used this
        combobox = new QComboBox(this);
        Is it the proper way to do it ?

        P Offline
        P Offline
        p3c0
        Moderators
        wrote on 27 Jun 2015, 12:45 last edited by p3c0
        #13

        @Ratzz Correct. Now the rest should work. Just don't forget to change the slot's definition.

        157

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Ratzz
          wrote on 27 Jun 2015, 12:48 last edited by
          #14

          @p3c0 Why to change the slot definition?

          --Alles ist gut.

          P 1 Reply Last reply 27 Jun 2015, 12:53
          0
          • R Ratzz
            27 Jun 2015, 12:48

            @p3c0 Why to change the slot definition?

            P Offline
            P Offline
            p3c0
            Moderators
            wrote on 27 Jun 2015, 12:53 last edited by
            #15

            @Ratzz Because in you have connected the signal activated to slot m_combobox which takes one argument.
            connect(combobox,SIGNAL (activated(int)),this,SLOT(m_combobox(int)));
            But there is no such slot defined with single argument and thus the connection will fail as it will not be able to find that slot. You have a slot m_combobox() which takes no arguments.

            157

            1 Reply Last reply
            0
            • R Offline
              R Offline
              Ratzz
              wrote on 27 Jun 2015, 12:53 last edited by
              #16

              @p3c0
              i used setGeometry() to assign position

              •  pushbutton->setGeometry(QRect(QPoint(100, 200),QSize(90, 40)));
                

              How to do use move();?

              --Alles ist gut.

              P 1 Reply Last reply 27 Jun 2015, 12:56
              0
              • R Ratzz
                27 Jun 2015, 12:53

                @p3c0
                i used setGeometry() to assign position

                •  pushbutton->setGeometry(QRect(QPoint(100, 200),QSize(90, 40)));
                  

                How to do use move();?

                P Offline
                P Offline
                p3c0
                Moderators
                wrote on 27 Jun 2015, 12:56 last edited by
                #17

                @Ratzz pushbutton->move(10,100). See http://doc.qt.io/qt-5/qwidget.html#pos-prop
                But as said earlier its best to use Layouts. See using Layouts for more details.

                157

                1 Reply Last reply
                1
                • R Offline
                  R Offline
                  Ratzz
                  wrote on 27 Jun 2015, 12:58 last edited by
                  #18

                  @p3c0 Can you give me rough sketch for my slot?

                  --Alles ist gut.

                  P 1 Reply Last reply 27 Jun 2015, 13:01
                  0
                  • R Ratzz
                    27 Jun 2015, 12:58

                    @p3c0 Can you give me rough sketch for my slot?

                    P Offline
                    P Offline
                    p3c0
                    Moderators
                    wrote on 27 Jun 2015, 13:01 last edited by
                    #19

                    @Ratzz
                    connect(combobox,SIGNAL (activated(int)),this,SLOT(m_combobox(int))); -> This is correct
                    mainwindow.h

                    private slots:
                        void m_combobox(int index);
                    

                    mainwindow.cpp

                    void MainWindow::m_combobox(int index)
                    {
                        label->setText("1");
                    }
                    

                    157

                    1 Reply Last reply
                    1
                    • R Offline
                      R Offline
                      Ratzz
                      wrote on 27 Jun 2015, 13:09 last edited by
                      #20

                      @p3c0
                      Thank you.
                      I will try using Layouts.

                      --Alles ist gut.

                      P 1 Reply Last reply 27 Jun 2015, 13:29
                      0
                      • R Ratzz
                        27 Jun 2015, 13:09

                        @p3c0
                        Thank you.
                        I will try using Layouts.

                        P Offline
                        P Offline
                        p3c0
                        Moderators
                        wrote on 27 Jun 2015, 13:29 last edited by
                        #21

                        @Ratzz You're Welcome :)
                        Since you are new here few more forum related reminders:

                        • Always surround the code blocks with ``` (3 backticks) while posting so that it gets nicely formatted and thus more readable for others.
                        • Mark the post as solved by editing the post title and prepending [Solved]

                        Happy Qt Coding ...

                        157

                        1 Reply Last reply
                        1
                        • R Offline
                          R Offline
                          Ratzz
                          wrote on 29 Jun 2015, 04:44 last edited by
                          #22

                          @p3c0
                          Sure :)

                          --Alles ist gut.

                          1 Reply Last reply
                          0

                          20/22

                          27 Jun 2015, 13:09

                          • Login

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