Qt C2665:连接错误

时间:2015-04-10 17:13:02

标签: c++ qt

我有一个类,其工作是运行命令行二进制文件并在每次收到stdout时发出信号......但是下面的代码给出了Qt connect错误。怎么了?

错误:

ffmpegcmd.cpp:39: error: C2665: 'QObject::connect' : none of the 3 overloads could convert all the argument types
C:\Qt\5.3\msvc2013_64\include\QtCore/qobject.h(205): could be 'QMetaObject::Connection QObject::connect(const QObject *,const char *,const char *,Qt::ConnectionType) const'
C:\Qt\5.3\msvc2013_64\include\QtCore/qobject.h(201): or       'QMetaObject::Connection QObject::connect(const QObject *,const QMetaMethod &,const QObject *,const QMetaMethod &,Qt::ConnectionType)'
C:\Qt\5.3\msvc2013_64\include\QtCore/qobject.h(198): or       'QMetaObject::Connection QObject::connect(const QObject *,const char *,const QObject *,const char *,Qt::ConnectionType)'
while trying to match the argument list '(QProcess *, const char *, FFMPEGCMD *const , const char *)'

课程:

bool FFMPEGCMD::runCommand(QStringList parameters)
{
    /*
     * Enforce one ffmpeg thread per class instance otherwise multiple processes
     * will emit signals to the same slot. Make sure running variable is set
     * before ffmpeg process is started.
     */
    if (this->running)
        return false;

    this->running = true;

    /*
     * Run ffmpeg in a new thread, passing signalling it's per line output int
     * the output slot for other code to handle output with.
     */
    this->process = new QProcess();
    this->process->start(this->ffmpeg_binary, parameters);

    QObject::connect(this->process, SIGNAL(readyReadStandardOutput()), this, SLOT(ffmpegOutputReady()));
}

/**
 * @brief FFMPEGCMD::ffmpegOutput Gets fired when FFMPEG gives an output, emits
 * the ffmpeg line
 */
void FFMPEGCMD::ffmpegOutputReady()
{
    emit ffmpegLine(this->process->readAllStandardOutput());
}

标题:

class FFMPEGCMD
{
public:
    FFMPEGCMD();
    bool runCommand(QStringList parameters);
private:
    QProcess *process;
    bool running;
    QString ffmpeg_binary;
private slots:
    void ffmpegOutputReady();
public slots:
    void ffmpegLine(QString line);
};

1 个答案:

答案 0 :(得分:1)

如果您发布的代码代表您的实际代码,那么您会遇到以下问题。

  

类FFMPEGCM

首先,您没有从任何Qt类继承。您至少需要继承QObject

class FFMPEGCOM : public QObject

其次,您需要在班级中使用Q_OBJECT宏,并确保该对象 moc' 。这是创建插槽所必需的。