main.cpp:1:24: fatal error: QApplication: No such file or directory

版权声明:原创博文,转载请注明出处! https://blog.csdn.net/sunriver2000/article/details/81712154

QT版本:5.7.0

代码:

#include <QApplication>
#include <QLineEdit>
#include <QPushButton>
#include <QLabel>
#include <QWidget>
#include <QHBoxLayout>
#include <QVBoxLayout>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QLabel *infoLabel = new QLabel;
    QLabel *cmdLabel = new QLabel;
    QLineEdit *cmdLineEdit = new QLineEdit;

    QPushButton *submitButton = new QPushButton;
    QPushButton *cancelButton = new QPushButton;
    QPushButton *browseButton = new QPushButton;

    infoLabel->setText("Please input command in lineedit");
    cmdLabel->setText("Open:");

    cmdLineEdit->clear();
    submitButton->setText("Submit");
    cancelButton->setText("Cancel");
    browseButton->setText("browse");

    QHBoxLayout *cmdLayout = new QHBoxLayout;
    cmdLayout->addWidget(cmdLabel);
    cmdLayout->addWidget(cmdLineEdit);

    QHBoxLayout *buttonLayout = new QHBoxLayout;
    buttonLayout->addWidget(submitButton);
    buttonLayout->addWidget(cancelButton);
    buttonLayout->addWidget(browseButton);

    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addWidget(infoLabel);
    mainLayout->addLayout(cmdLayout);
    mainLayout->addLayout(buttonLayout);

    QWidget *window = new QWidget;
    window->setLayout(mainLayout);
    window->setWindowTitle("Running...");
    window->show();

    //MainWindow w;
    //w.show();

    return a.exec();
}

编译步骤:

1、qmake -project

2、qmake

3、mingw32-make

错误:

main.cpp:1:24: fatal error: QApplication: No such file or directory

解决方法:

1、在layout.pro的最后添加QT  += widgets

2、重新编译。

猜你喜欢

转载自blog.csdn.net/sunriver2000/article/details/81712154
今日推荐