QProcess和分段错误错误

时间:2011-10-28 14:24:32

标签: qt qt4 signals qprocess

我正在编写程序构建器类。我有一个分段错误。

#ifndef BUILDER_H
#define BUILDER_H

#include <QObject>
#include <QProcess>
#include <QDir>
#include <QFileInfo>

class Builder : public QProcess
{
Q_OBJECT
public:
    explicit Builder(QObject *parent = 0);
    void loadSource(QString fpath);
    bool isBuilded();

private:
    QProcess* shell;
    QString source;
    QString path;
    QString module;

signals:
    void sourceLoaded();
    void builded();

protected slots:
    void build();

};

#endif // BUILDER_H

和.cpp:

#include "builder.h"

Builder::Builder(QObject *parent) :
    QProcess(parent)
{
    connect(this,SIGNAL(sourceLoaded()),this,SLOT(build()));
    connect(this,SIGNAL(finished(int)),this,SIGNAL(builded()));
}

void Builder::loadSource(QString fpath)
{
    source = fpath;
    QFileInfo info(source);
    path = info.absoluteDir().absolutePath();
    module = path+info.baseName();
    emit sourceLoaded();
}

bool Builder::isBuilded()
{
    if(QFile::exists(module))
        return true;
    return false;
}

void Builder::build()
{
    QStringList argv;
    argv << source;
    start("g++",argv);
}

并且我也在运行代码(MainWindow.cpp):

void MainWindow::initConnections()
{
    connect(ui->sourceBrowse,SIGNAL(clicked()),this,SLOT(ui_sourceBrowseButtonClicked()));
}
void MainWindow::ui_sourceBrowseButtonClicked()
{
    connect(compiler,SIGNAL(finished()),this,SLOT(programBuilded()));
    compiler->loadSource("//home//tucnak//dev//polygon//testdir//program.cpp");
}

void MainWindow::programBuilded()
{
    if(compiler->isBuilded())
        qDebug() << "Builded";
}

我的代码必须编译在loadSource(QString)中提供的程序。

当我启动start()时,函数程序返回SISSEGV信号。我没有看到错误。

0 个答案:

没有答案