gpt4 book ai didi

c++ - Qt C2665 :connect error

转载 作者:行者123 更新时间:2023-11-28 06:19:29 27 4
gpt4 key购买 nike

我有一个类负责运行命令行二进制文件并在每次收到标准输出时发出信号...但是以下代码给出了 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);
};

最佳答案

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

class FFMPEGCM

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

class FFMPEGCOM : public QObject

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

关于c++ - Qt C2665 :connect error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29567092/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com