In your main.cpp have something like this:
{
//make layouts and buttons
//connect button and function
connect(myButton, SIGNAL(clicked()), this, SLOT(myFunction()));
//set layouts and buttons
mainLayout->addLayout(buttonLayout);
buttonLayout->addWidget(myButton);
setLayout(mainLayout);
}
MyWidget::MyWidget(QWidget* parent): QWidget(parent)
{
//make layouts and buttons
mainLayout = new QVBoxLayout;
statusLayout = new QHBoxLayout;
myButton = new QPushButton("Button");
//connect button and function
connect(myButton, SIGNAL(clicked()), this, SLOT(myFunction()));
//set layouts and buttons
mainLayout->addLayout(buttonLayout);
buttonLayout->addWidget(myButton);
setLayout(mainLayout);
}
To copy to clipboard, switch view to plain text mode
Then you would call this from your main function:
int main(int argc, char *argv[])
{
MyWidget window;
window.show();
return application.exec();
}
int main(int argc, char *argv[])
{
QApplication application(argc, argv);
MyWidget window;
window.show();
return application.exec();
}
To copy to clipboard, switch view to plain text mode
Of course your *.h file will need to declare the buttons and layouts accordingly. Like this:
{
Q_OBJECT
public:
public slots:
void myFunction(void);
private:
}
class MyWidget : public QWidget
{
Q_OBJECT
public:
MyWidget (QWidget* parent = 0);
public slots:
void myFunction(void);
private:
QVBoxLayout* mainLayout;
QHBoxLayout* buttonLayout;
QPushButton* myButton;
}
To copy to clipboard, switch view to plain text mode
Hope that helped a bit.
Bookmarks