Home:ALL Converter>Qt: QObject::connect: Cannot connect (null)

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

Ask Time:2011-06-05T02:01:25         Author:jonathan topf

Json Formatter

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!.

Author:jonathan topf,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/6238486/qt-qobjectconnect-cannot-connect-null
Mat :

You need to create the proc and procLog objects.\n\nYou've only got pointers as class members, so you'll have to initialize those (with new). connect only works on live objects.",
2011-06-04T18:06:38
yy