Qt C ++编译在没有程序显示的情况下完成

时间:2016-03-31 09:43:39

标签: c++ qt

所以我构建了一个Qt简单的应用程序,在看到一个Window之前程序崩溃了,这里是代码:

First.pro:

#-------------------------------------------------
#
# Project created by QtCreator 2016-03-31T18:48:54
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = First
TEMPLATE = app


SOURCES += main.cpp\
        mainwindow.cpp

HEADERS  += mainwindow.h

FORMS    += mainwindow.ui

mainwindow.h:

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

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;
};

#endif // MAINWINDOW_H

main.cpp中:

#include "mainwindow.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
}

mainwindow.cpp:

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{
    ui->label->setText("Pushed!"); // Just this

}

每当我点击左侧的运行按钮时,它就会成功编译,但我没有看到任何问题?我正在使用&#34; Qt 5.6.0 for Windows 32-bit(MinGW 4.9.2,1.0 GB)&#34;顺便说一句。

1 个答案:

答案 0 :(得分:1)

回答我的问题是,您必须将目录中的所有.dll文件: C:\ Qt \ Qt5.6.0 \ 5.6 \ mingw49_32 \ bin 复制到您的构建文件夹。在我的情况下它是: C:\ Users \ Fur \ Documents \ Programming \ build-First-Desktop_Qt_5_6_0_MinGW_32bit-Release \ release 是的我正在使用发布配置文件,因为性能更高,并且不会比Debug更多地占用资源。复制所有.dll文件后,只需删除该构建文件夹中的所有.dll文件即可清理它(确保您的可执行文件正在运行时执行此操作)。这是为了清理你的构建文件夹,所需的.dll文件将保留;)