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.
ui->label->repaint();immediately after just to help debug a little. Also put aqDebug/ breakpoint in there to make sure the member function is actually getting called.qDebug() << "TEST";- if you can get error saying it's undefined or something make sure you include theQDebugheader. More info can be found here doc.qt.io/qt-5/qdebug.html