0

Sorry about the other duplicate post. The one I was referred to helped out a lot but it isn't compiling.

QProcess *proc = new QProcess;
connect(proc, SIGNAL(readyRead()), this, SLOT(updateText()));
proc->start("pathToScript");

The second line gives me this error,

error: expected constructor, destructor, or type conversion before '(' token

and the third gives me this one,

error: 'proc' does not name a type

Edit: The rest of my code.

ThiWindow.h:

#ifndef THIWINDOW_H
#define THIWINDOW_H

#include <QMainWindow>

namespace Ui {
class ThiWindow;
}

class ThiWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit ThiWindow(QWidget *parent = 0);
    ~ThiWindow();

signals:
    void readyRead();


private slots:
    void updateText();

private:
    Ui::ThiWindow *ui;

};

ThiWindow.cpp:

#endif // THIWINDOW_H
#include "thiwindow.h"
#include "ui_thiwindow.h"
#include <QProcess>

QProcess *proc = new QProcess;
connect(proc, SIGNAL(readyRead()), this, SLOT(updateText()));
proc->start("pathToScript");

ThiWindow::ThiWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::ThiWindow)
{
    ui->setupUi(this);
}

ThiWindow::~ThiWindow()
{
    delete ui;
}




void ThiWindow::updateText()
{
    QString appendText(proc->readAll());
    ui->textEdit->append(appendText);

}

and main.cpp:

#include "mainwindow.h"
#include "mainwindow.cpp"
#include <QApplication>
using namespace std;


int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow qw;
        qw.show();
    return a.exec();
}

Please Help,

Brooks Rady

4

2 回答 2

0

MOC 文件生成将您的类定义为启用 Qt 的对象。

这允许您使用connect没有命名空间前缀的函数。您在connect未定义对象的“通用区域”中使用它,这就是您收到(错误的原因。

如果我是你,我会搬家

QProcess *proc = new QProcess;
connect(proc, SIGNAL(readyRead()), this, SLOT(updateText()));
proc->start("pathToScript");

在您的构造函数中。然后它应该工作。

于 2013-09-09T20:04:52.000 回答
0

将 QProcess *proc 放入 mainwindow.h 的私有部分。之后,您需要在 MainWindow 构造函数和 SIGNAL/SLOT 中分配内存(proc = new QProcess;),您也需要在构造函数中实现。对不起我的英语不好!

于 2013-09-09T03:59:16.417 回答