Qt: QObject::connect: Cannot connect (null)
Ich versuche, schließen Sie ein signal von einem QProcess
in meinem mainwindow()
Objekt zu einem anderen QObject
Basis-Klasse in meinem mainwindow()
- Objekt, aber ich bekomme diese Fehlermeldung:
QObject::connect: Cannot connect (null)::readyReadStandardOutput () to (null)::logReady()
Hier ist der code nicht komplett durch mit allen Mitteln, aber ich weiß nicht, warum es nicht funktioniert.
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;
}
Dank!.
Ich weiß nicht, was compiler und Fahnen, die Sie verwenden, aber Sie haben Glück, Sie wurden sogar null. Es wäre viel schwieriger, herauszufinden, hatte Sie schon einige random-memory-Adressen.
InformationsquelleAutor jonathan topf | 2011-06-04
Du musst angemeldet sein, um einen Kommentar abzugeben.
Müssen Sie zum erstellen der
proc
undprocLog
Objekte.Du hast nur Zeiger als Schüler, so müssen Sie initialisieren Sie diese (mit
new
).connect
funktioniert nur auf der live-Objekte.machen einen neuen thread auf stackoverflow für jede Frage 🙂
InformationsquelleAutor Mat
proc ist ein Zeiger, aber nicht alles. Sie instanziieren ein qprocess, bevor Sie es anschließen!
InformationsquelleAutor Alessandro Pezzato