Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    QPushButton to activate widget.show()

    General and Desktop
    4
    10
    4990
    Loading More Posts
    • 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
      sheehan1234 last edited by

      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 Reply Quote 0
      • P
        picasoft last edited by

        What the base class of your widget?

        1 Reply Last reply Reply Quote 0
        • E
          Eddy last edited by

          Is widget available in the scope?

          Where did you put the connect?

          Qt Certified Specialist
          www.edalsolutions.be

          1 Reply Last reply Reply Quote 0
          • S
            sheehan1234 last edited by

            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 Reply Quote 0
            • E
              Eddy last edited by

              Where did you put your button?

              Qt Certified Specialist
              www.edalsolutions.be

              1 Reply Last reply Reply Quote 0
              • S
                sheehan1234 last edited by

                also in the main

                1 Reply Last reply Reply Quote 0
                • E
                  Eddy last edited by

                  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 Reply Quote 0
                  • S
                    sheehan1234 last edited by

                    @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 Reply Quote 0
                    • E
                      Eddy last edited by

                      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 Reply Quote 0
                      • G
                        goetz last edited by

                        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 Reply Quote 0
                        • First post
                          Last post