qt_base
main.cpp
#include "hellowidget.h"
#include <QApplication>
#include <QLocale>
#include <QTranslator>
#include<iostream>
int main(int argc, char *argv[]){
//maintain qt application life object everyone only has one object
QApplication a(argc, argv);
// windows project
HelloWidget w;
w.show();
std::cout<<"before exec"<<std::endl;
a.exec();
std::cout<<"after exec"<<std::endl;
return 0;
}
hellowidget
#ifndef HELLOWIDGET_H
#define HELLOWIDGET_H
#include <QWidget>
class HelloWidget : public QWidget
{
//宏,引入qt信号和槽的一个宏
Q_OBJECT
public:
//parent窗口指针 父窗口对象的指针
//如果parent为0或者nullptr 表示当前窗口对象是一个顶层窗口
//顶层窗口就是在任务栏可以找到的窗口
HelloWidget(QWidget *parent = nullptr);
~HelloWidget();
};
#endif // HELLOWIDGET_H