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. QPushButton to activate widget.show()
QtWS25 Last Chance

QPushButton to activate widget.show()

Scheduled Pinned Locked Moved General and Desktop
10 Posts 4 Posters 5.5k 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.
  • S Offline
    S Offline
    sheehan1234
    wrote on last edited by
    #1

    does anyone know why this won't work?

    @QObject::connect(button, SIGNAL(clicked()), widget, SLOT(show());@

    button is my QPushButton
    I'm trying to perform the operation; widget.show() whenever it gets clicked

    1 Reply Last reply
    0
    • P Offline
      P Offline
      picasoft
      wrote on last edited by
      #2

      What the base class of your widget?

      1 Reply Last reply
      0
      • EddyE Offline
        EddyE Offline
        Eddy
        wrote on last edited by
        #3

        Is widget available in the scope?

        Where did you put the connect?

        Qt Certified Specialist
        www.edalsolutions.be

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sheehan1234
          wrote on last edited by
          #4

          widget is available, this is in my main method. i have previous calls to widget in the main. I originally had "widget.show();" which worked properly. I'm trying to add a button that will make it happen.

          1 Reply Last reply
          0
          • EddyE Offline
            EddyE Offline
            Eddy
            wrote on last edited by
            #5

            Where did you put your button?

            Qt Certified Specialist
            www.edalsolutions.be

            1 Reply Last reply
            0
            • S Offline
              S Offline
              sheehan1234
              wrote on last edited by
              #6

              also in the main

              1 Reply Last reply
              0
              • EddyE Offline
                EddyE Offline
                Eddy
                wrote on last edited by
                #7

                Can you show your main then? I suspect you didn't put the button in a dialog or mainwindow. How do you show your button so you can click it?

                Qt Certified Specialist
                www.edalsolutions.be

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  sheehan1234
                  wrote on last edited by
                  #8

                  @int main(int argc, char *argv[])
                  {
                  QApplication app(argc, argv);
                  MyWidget widget;
                  widget.betaNum = 20;

                  QWidget *win = new QWidget;
                  QVBoxLayout *layout = new QVBoxLayout;
                  QComboBox *combo = new QComboBox;
                  QPushButton *button = new QPushButton("Plot");
                  combo->addItem("1");
                  combo->addItem("2.000001");
                  combo->addItem("4");
                  layout->addWidget(combo);
                  layout->addWidget(button);
                  win->setLayout(layout);
                  win->show();
                  widget.stabreg = combo->itemData(combo->currentIndex()).toFloat();

                  QObject::connect(button, SIGNAL(clicked()), widget, SLOT(show());

                  return app.exec();
                  

                  }@

                  I have two widgets, one is the graph (widget) and the second one (win) is the one with a drop down menu

                  1 Reply Last reply
                  0
                  • EddyE Offline
                    EddyE Offline
                    Eddy
                    wrote on last edited by
                    #9

                    Why don't you use a QDialog instead of QWidget? A QWidget is meant to be used in another window not as a popup.

                    Qt Certified Specialist
                    www.edalsolutions.be

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      goetz
                      wrote on last edited by
                      #10

                      connect() takes object pointers (adresses) as arguments. As your widget is stack based, you need operator & to pass an address, so just change widget to &widget in the statement:

                      @
                      // WRONG
                      QObject::connect(button, SIGNAL(clicked()), widget, SLOT(show());

                      // right
                      QObject::connect(button, SIGNAL(clicked()), &widget, SLOT(show());
                      @

                      http://www.catb.org/~esr/faqs/smart-questions.html

                      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