我有一个Qt Ui作为指针作为成员。 如果我尝试在cpp中分配或使用该成员,它就不起作用。
有些额外的代码我不会显示,因为它不相关。
Krypto.h:
#pragma once
#include <ui_krypto.h>
#include <QMainWindow>
class Krypto : public QMainWindow
{
Q_OBJECT
public:
Krypto(QWidget * parent = NULL);
~Krypto();
private:
Ui::Krypto * Ui = NULL; //This is the Obj which couldn`t be used
};
Krypto.cpp:
#include "Krypto.h"
Krypto::Krypto(QWidget *parent) :
QMainWindow(parent)
{
ui = new Ui::Krypto(); //This don`t work
ui->setupUi(this); //And this don`t work
}
Krypto::~Krypto()
{
delete ui;
}
ui_krypto.h:
class Ui_Krypto
{
public:
QAction *actionCode_Encode;
QAction *actionKey;
QWidget *centralWidget;
QGroupBox *CodeEncodegroupBox;
QTextEdit *textausgabe;
QTextEdit *texteingabe;
QComboBox *CBAuswahl;
QCommandLinkButton *ReadyButton;
QLineEdit *KeyCodelineEdit;
QLabel *label;
QGroupBox *KeygroupBox;
QPushButton *gKeypushButton;
QLineEdit *keylineEdit;
...
void setupUi(QMainWindow *Krypto)
{
...
}
}
namespace Ui {
class Krypto: public Ui_Krypto {};
} // namespace Ui
答案 0 :(得分:-1)
您的班级成员应该被称为'ui'而不是'Ui'
class Krypto : public QMainWindow
{
...
private:
Ui::Krypto * ui = NULL;
};