c++ - Qt C++:信号和插槽参数不兼容
问题描述
我不知道这段代码有什么问题,我用来连接信号和排序的语法看起来是正确的,但由于某种原因,我一直收到这个错误
error: static assertion failed: Signal and slot arguments are not compatible.
# define Q_STATIC_ASSERT_X(Condition, Message) static_assert(bool(Condition), Message)
^
这是头文件的代码
include <QString>
#include <QStringList>
#include <QTextStream>
class filereader : public QObject
{
Q_OBJECT
public:
Q_PROPERTY(QString filename READ getFileName WRITE setFileName NOTIFY fileNameChanged)
Q_PROPERTY(QString output READ getOutput)
Q_PROPERTY(QString error READ getErrorString)
explicit filereader(QObject *parent = 0);
QString getFileName();
QString getOutput();
QString getErrorString();
void setFileName(const QString &fileName);
Q_INVOKABLE void readFile(); // this allows us to use this is as a function so we could do something like onClicked{ <text_id>.text = <file_reader_id>.readFile() }
signals:
void fileNameChanged();
void outputChanged(QString &Output);
void gotError(QString &&err);
void errorSignal();
protected slots:
void handleOut(QString &output);
void handleError(QString &err);
private:
QString fileName;
QString output;
QString error;
};
#endif // FILEREADER_H
这是源文件的代码
#include "filereader.h"
filereader::filereader(QObject *parent):
QObject(parent)
{
connect(this,&filereader::gotError,this,&filereader::handleError);
connect(this,&filereader::outputChanged,this,&filereader::handleOut);
}
QString filereader::getFileName()
{
return this->fileName;
}
QString filereader::getOutput()
{
return this->output;
}
QString filereader::getErrorString()
{
return this->error;
}
void filereader::setFileName(const QString &fileName)
{
if(this->fileName == fileName)
return;
this->fileName = fileName;
emit fileNameChanged();
}
void filereader::readFile()
{
QFile file(this->fileName);
if (file.open(QIODevice::ReadOnly))
{
QTextStream in(&file);
while (!in.atEnd())
{
QString line = in.readAll();
outputChanged(line);
qDebug() << line;
}
file.close();
file.flush(); // this flushes the file stream
}else{
gotError("Could not open the file!");
}
}
void filereader::handleOut(QString &output)
{
if(this->output == output)
return;
this->output = output;
}
void filereader::handleError(QString &err)
{
if(this->error == err)
return;
this->error = err;
emit errorSignal();
}
我是 Qt 和 Qml 的新手,所以请帮助我理解这个问题。谢谢 :)
解决方案
推荐阅读
- c# - HoloLens 用作 UDP 服务器,但不能用作客户端
- image - java带有循环的多个图像
- regex - 使用正则表达式换行
- bash - 正则表达式替换增量
- url - 使用proc报告为SAS中excel电子表格的每个选项卡创建页面顶部的链接
- apache-beam - 如何在 Apache Beam 2.4 中替换 withFilenamePolicy?
- javascript - React-router 不会在不同的路径上重新安装组件
- json - 如何将引用另一个对象的对象转换为 json Asp.net core
- android - Android Studio Gradle Sync 因公司代理失败:找不到有效的证书路径
- jquery - 如果窗口小于 1024 像素,文本锚将不起作用