新手刚接触Qt
程序代码:
#ifndef MYWIN_5_H #define MYWIN_5_H #include <QtWidgets/QMainWindow> # include <QPushButton> # include <QVBoxLayout> # include <QLineEdit> # include <QPlainTextEdit> #include "ui_mywin_5.h" class mywin_5 : public QMainWindow { Q_OBJECT public: mywin_5(QWidget *parent = 0); ~mywin_5(); private: // Ui::mywin_5Class ui; QPushButton * m_button; QLineEdit * m_lineEdit; QPlainTextEdit * m_textEdit; }; #endif // MYWIN_5_H 这是头文件 #include "mywin_5.h" mywin_5::mywin_5(QWidget *parent) : QMainWindow(parent) { // ui.setupUi(this); m_button = new QPushButton("Hello,Qt!",this); m_lineEdit = new QLineEdit(this); m_textEdit = new QPlainTextEdit(this); QVBoxLayout * layout1 = new QVBoxLayout(this); layout1->addWidget(m_lineEdit); layout1->addWidget(m_textEdit); layout1->addWidget(m_button); layout1->setSpacing(60); this->setLayout(layout1); } mywin_5::~mywin_5() { } 这是头文件实现的cpp文件 #include "mywin_5.h" #include <QtWidgets/QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); mywin_5 w; w.setWindowTitle("my window"); w.show(); return a.exec(); } 这是主函数
为什么会得到这样的一个窗口呢,
Button为什么不见了