Qt:QObject ::连接:无法连接(空)

发布于 11-13 09:40 字数 1733 浏览 1 评论 0原文

我正在尝试将来自 mainwindow() 对象内的 QProcess 的信号连接到我的 mainwindow() 内另一个基于 QObject 的类) 对象,但我收到此错误:

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

这是代码,它无论如何都不完整,但我不知道为什么它不起作用。

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

谢谢!

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

您需要创建 proc 和 procLog 对象。

您只有作为类成员的指针,因此您必须初始化它们(使用new)。 connect 仅适用于活动对象。

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.

她说她爱他2024-11-20 09:40:15

proc是一个指针,但它不指向任何东西。在连接 qprocess 之前,您必须实例化它!

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

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()));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文