2

So I build a Qt simple application, the program is crashing before you see a Window and here is the code:

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

}

Whenever I click the run button left down side, it compiles successfully but I don't see anything is there any problem? I am using "Qt 5.6.0 for Windows 32-bit (MinGW 4.9.2, 1.0 GB)" by the way.

10
  • Although it's not necessarily a "proper" solution, try adding ui->label->repaint(); immediately after just to help debug a little. Also put a qDebug / breakpoint in there to make sure the member function is actually getting called. Commented Mar 31, 2016 at 9:48
  • Hi there OMGtechy, where should I put qDebug exactly? How to implement that exactly? Commented Mar 31, 2016 at 9:57
  • qDebug() << "TEST";- if you can get error saying it's undefined or something make sure you include the QDebug header. More info can be found here doc.qt.io/qt-5/qdebug.html Commented Mar 31, 2016 at 9:58
  • Okay this was from the application output: Starting C:\Users\Fur\Documents\Programming\build-First-Desktop_Qt_5_6_0_MinGW_32bit-Debug\debug\First.exe... The program has unexpectedly finished. C:\Users\Fur\Documents\Programming\build-First-Desktop_Qt_5_6_0_MinGW_32bit-Debug\debug\First.exe crashed Commented Mar 31, 2016 at 10:02
  • 1
    One quick question, you do have a main function executing the application right? Commented Mar 31, 2016 at 10:13

1 Answer 1

1

Answer to my problem is that, you have to copy the all the .dll files from the directory: C:\Qt\Qt5.6.0\5.6\mingw49_32\bin to your build folder. In my case it is: C:\Users\Fur\Documents\Programming\build-First-Desktop_Qt_5_6_0_MinGW_32bit-Release\release Yes I am using release profile because higher performance and does not eat resources much than Debug. After you copied all the .dll files just clean it up by deleting all .dll files from that build folder(make sure that your executable is running while doings this). This is to clean up your build folder and the needed .dll files will stay ;)

Sign up to request clarification or add additional context in comments.

3 Comments

you may also check the Options of Build & Run if everything is setup correctly there(to be able to run from QtCreator).. very tricky to delete dlls while running the app :)
Yep because it will argue that the dll is being used by the running app hahaha, kinda tricky yes. Because using all of those .dll files is really heavy in your drive like 1GB+ :O
yes this trick will work unless there are no plugins involved (which are loaded ondemand at runtime I guess), but again if they are already loaded then this trick will work properly

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.