我正在试着写我的新应用,但每次我在QDialog上按一个按钮,它就会崩溃。
下面是我的代码:
mainwindow.h
#include <QMainWindow>
#include "creatlist.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
QDialog* creatList;
public slots:
void tableFull(){
...some code here...
}
private:
Ui::MainWindow *ui;
};creatlist.h:
#include <QDialog>
#include "mainwindow.h"
namespace Ui {
class creatlist;
}
class MainWindow;
class creatlist : public QDialog
{
Q_OBJECT
public:
explicit creatlist(QWidget *parent = 0);
~creatlist();
MainWindow* mainwindow;
signals:
void updateList();
public slots:
void ready(){
///////////////////////////////////////////////////////////crash
connect(this,SIGNAL(updateList()),mainwindow,SLOT(tableFull()));
emit updateList();
}
private:
Ui::creatlist *ui;
};如果我试图发送一些信号,我的应用程序会崩溃,并出现分段故障。
我做到了:
void creatlist::ready()
{
mainwindow = new MainWindow(this);
emit mainwindow->linktableFull();
}但是如果我尝试在linktableFull()中执行QTextBroser.append("hue hue");,QTextBrowser总是空的。
发布于 2015-04-21 18:08:42
您的QTextBrowser始终为空,因为您在每个ready()函数中创建了新的mainwindow对象。您应该只创建一次主窗口对象,并在整个代码中使用相同的mainwindow对象。您可以在creatlist构造函数中创建新的mainwindow对象。
https://stackoverflow.com/questions/29048780
复制相似问题