Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt: QObject::connect: Cannot connect (null)

Tags:

qt

qt4

qt-creator

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

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

Heres the code, its not complete by any means but I don't know why it doesn't 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!.

like image 932
jonathan topf Avatar asked Jun 04 '11 18:06

jonathan topf


2 Answers

You need to create the proc and procLog objects.

You've only got pointers as class members, so you'll have to initialize those (with new). connect only works on live objects.

like image 77
Mat Avatar answered Nov 02 '22 21:11

Mat


proc is a pointer, but it does not point to anything. You have to instantiate a qprocess before you connect it!

proc = new QProcess();
connect(proc, SIGNAL(readyReadStandardOutput ()), procLog, SLOT(logReady()));
like image 1
Alessandro Pezzato Avatar answered Nov 02 '22 20:11

Alessandro Pezzato