Reputation: 133
I trying to rewrite a project from python to c++. I imported the form into my project, but when accessing it, a runtime error occurs (see below) I can access the methods of the form, but when executed, it gives an error
below is all the code involved
plaindict.h
#include <QDialog>
#include "ui_plaindict.h"
namespace Ui {
class PlainDict;
}
class PlainDict : public QDialog
{
Q_OBJECT
public:
explicit PlainDict(QDialog *parent = nullptr);
~PlainDict();
private:
Ui::PlainDict *ui;
};
plaindict.cpp
#include "plaindict.h"
#include "ui_plaindict.h"
PlainDict::PlainDict(QDialog *parent) :
QDialog(parent),
ui(new Ui::PlainDict)
{
ui->inputLine->setText("regetrg");
ui->setupUi(this);
}
PlainDict::~PlainDict()
{
delete ui;
}
main.cpp
#include "plaindict.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
PlainDict w;
w.show();
return a.exec();
}
and pro file
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = PlainDict
TEMPLATE = app
DEFINES += QT_DEPRECATED_WARNINGS
CONFIG += c++11
SOURCES += \
main.cpp \
plaindict.cpp \
modelfororiginal.cpp
HEADERS += \
plaindict.h \
modelfororiginal.h\
FORMS += \
plaindict.ui
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
Upvotes: 0
Views: 99
Reputation: 62858
ui->inputLine->setText("regetrg");
ui->setupUi(this);
Here you access inputLine
before it is initialized by that setupUi
call.
To fix, switch order of these lines.
Upvotes: 2