Get Started!
Open a new project
Choose Qt widget Application to create a desktop application.
A blank project is consist of these files below:
- main.cpp
- mainwindow.cpp, mainwindow.h, mainwindow.ui
- *.pro
mainwindow is where you design your user interface. The *.pro file stores the library, include library paths. It also records the project related files path, and the compile flags.
Open a project from another computer
If you want to open a project from another computer, Qt will ask if you want to load the Qt's *.user settings file, press No.
Reconfigure your project, in this case, we'll check Desktop Qt 5.3 MSVC2013 OpenGL 64bit.
A new *.pro.user will be created, and the old one will be renamed as a backup file.
The mainwindow class
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
The code written inside the braces executes when the application enter the mainwindow class. You can initial your values here.
If you are using any compiler that supports C++11 or above, you can also initial part of your variables in the header file.
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_pushButton_clicked();
private:
Ui::MainWindow *ui;
//Initialization
int hello = 1;
};
The code below executes when the application exit the mainwindow class. If you want to release memory or something else, you can write your code here.
MainWindow::~MainWindow()
{
delete ui;
}