简体   繁体   中英

QT program crashes after connect()

I'm trying to write my new app, but it crashes every time I press a button on QDialog.

Here's my code :

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;
};

If i try to send some signals my app crashes with a Segmentation Fault.

I did:

void creatlist::ready()
{
mainwindow = new MainWindow(this);
emit mainwindow->linktableFull();
}

but if I try to do QTextBroser.append("hue hue"); in linktableFull(), QTextBrowser is always empty.

Your QTextBrowser always empty because you create new mainwindow object in every ready() function. You should create mainwindow object once and use same mainwindow object throughout code. You can create new mainwindow object in creatlist constructor.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM