First i opened the QTCreator from the Applications->Programming menu. Then went to File->New. And followed the steps as shown in the pictures.





After the project is created, i opened the mainwindow.ui and dragged a PushButton to the center of the main window. From the property, i changed the display text of the button as Hello World. its name is changed to HelloWorldBtn.

Then i added a private slot in the mainwindow.h file as follows:
private slots:
void on_HelloWorldBtn_clicked();
It means the signal connection is automatic.
Then i added the following handler function in the mainwindow.cpp file:
void MainWindow::on_HelloWorldBtn_clicked()
{
QMessageBox::information(this,"Som", "Hello World");
}
And its done... Of course to compile this code, i had to do #include (QMessageBox) in the mainwindow.cpp file...
i ran the application... And when i clicked the button it showed the messagebox as the following picture...

No comments:
Post a Comment