一、方法
获取信号槽返回值的方法有三种:
(1)通过形参的方式,传递引用或者指针。(未写例子)
(2)直接在信号发出位置获取返回值。(下面有例子)
(3)通过QMetaObject::invokeMethod方法。(具体使用可以参考QT的帮助文档或者看下面的代码实例)
二、代码
#ifndef WRITETHREAD_H
#define WRITETHREAD_H
#include <QObject>
class WriteThread : public QObject
{
Q_OBJECT
public:
WriteThread(QObject *parent = nullptr);
public slots:
QString slotWrite(QString str);
signals:
};
#endif // WRITETHREAD_H
#include "writethread.h"
#include <QDebug>
#include <QDateTime>
#include <QThread>
WriteThread::WriteThread(QObject *parent) : QObject(parent)
{
}
QString WriteThread::slotWrite(QString str)
{
qDebug()<<"执行了slotWrite 子线程id:"<<QThread::currentThreadId();
QThread::sleep(3);
QString date = "