Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QPushButton to activate widget.show()



  • 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



  • What the base class of your widget?



  • Is widget available in the scope?

    Where did you put the connect?



  • 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.



  • Where did you put your button?



  • also in the main



  • 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?



  • @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



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



  • 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());
    @


Log in to reply