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 -
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.
-
also in the main
-
@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
-
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());
@