Qt: QObject :: connect: cannot connect (null)

I am trying to connect a signal from QProcess inside my mainwindow() object to another QObject class inside my mainwindow() object, but I get this error:

 QObject::connect: Cannot connect (null)::readyReadStandardOutput () to (null)::logReady() 

Here is the code, it is not completed in any way, but I do not know why it does not work.

exeProcess.h

 #ifndef EXEPROCESS_H #define EXEPROCESS_H #include <QObject> class exeProcess : public QObject { Q_OBJECT public: explicit exeProcess(QObject *parent = 0); signals: void outLog(QString outLogVar); //will eventually connect to QTextEdit public slots: void logReady(); }; #endif // EXEPROCESS_H 

exeProcess.cpp

 #include "exeprocess.h" exeProcess::exeProcess(QObject *parent) : QObject(parent) { } void exeProcess::logReady(){ } 

mainwindow.h

 #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QProcess> #include "exeprocess.h" /*main window ---------------------------------------*/ namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); QProcess *proc; exeProcess *procLog; public slots: private: Ui::MainWindow *ui; }; #endif // MAINWINDOW_H 

mainwindow.cpp

 #include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); connect(proc, SIGNAL(readyReadStandardOutput ()), procLog, SLOT(logReady())); } MainWindow::~MainWindow() { delete ui; } 

Thanks!.

+6
source share
2 answers

You need to create the proc and procLog .

You only have pointers as members of the class, so you have to initialize them (with new ). connect only works with live objects.

+9
source

proc is a pointer, but it does not point to anything. You must create an qprocess instance before connecting it!

 proc = new QProcess(); connect(proc, SIGNAL(readyReadStandardOutput ()), procLog, SLOT(logReady())); 
0
source

Source: https://habr.com/ru/post/889780/


All Articles