我试图与此传递我的班次低谷的信号:
connect(this, SIGNAL(SIG_connectSerial(SerialSetting::Settings)), serial, SLOT(openConnection(SerialSetting::Settings)),Qt::QueuedConnection);
我要通过的课程是该课程:
#ifndef SERIALSETTING_H
#define SERIALSETTING_H
#include <QWidget>
#include <QtSerialPort/QSerialPort>
namespace Ui {
class SerialSetting;
}
class QIntValidator;
class SerialSetting : public QWidget
{
Q_OBJECT
public:
struct Settings {
QString portName;
qint32 baudRate;
};
Settings settings();
public:
explicit SerialSetting(QWidget *parent = 0);
~SerialSetting();
private slots:
void apply();
void on_btnApply_clicked();
private:
void fillPortsParameters();
void fillPortsInfo();
void updateSettings();
private:
Ui::SerialSetting *ui;
Settings currentSettings;
QIntValidator *intValidator;
};
#endif // SERIALSETTING_H
#include "serialsetting.h"
#include "ui_serialsetting.h"
#include <QtSerialPort/QSerialPortInfo>
#include <QIntValidator>
#include <QLineEdit>
QT_USE_NAMESPACE
static const char blankString[] = QT_TRANSLATE_NOOP("SettingsDialog", "N/A");
SerialSetting::SerialSetting(QWidget *parent) :
QWidget(parent),
ui(new Ui::SerialSetting)
{
ui->setupUi(this);
intValidator = new QIntValidator(0, 4000000, this);
//ui->cboBaudRate->setInsertPolicy(QComboBox::NoInsert);
fillPortsParameters(); //call function to fill comboboxes
connect(ui->btnApply, SIGNAL(clicked()),this, SLOT(apply()));
}
SerialSetting::~SerialSetting()
{
delete ui;
}
void SerialSetting::fillPortsParameters()
{
//fill cboComport with all available comports
foreach(const QSerialPortInfo &info, QSerialPortInfo::availablePorts())
{
ui->cboComport->addItem(info.portName());
}
}
void SerialSetting::apply()
{
SerialSetting::currentSettings.portName = ui->cboComport->currentText();
hide();
}
SerialSetting::Settings SerialSetting::settings()
{
return SerialSetting::currentSettings;
}
void SerialSetting::on_btnApply_clicked()
{
}
编译器抛出此异常:
QObject :: connect:无法将'SerialSetting :: Settings'类型的参数排队
(确保使用qRegisterMetaType()注册了“ SerialSetting :: Settings”。)
我尝试了
qRegisterMetaType<SerialSetting>();
,但这以以下错误结束:static assertion failed: Type is not registered, please use the Q_DECLARE_METATYPE macro to make it known to Qt's meta-object system
#define Q_STATIC_ASSERT_X(Condition, Message) static_assert(bool(Condition), Message)
在类标题的末尾添加Makro
Q_DECLARE_METATYPE(Ui::SerialSetting)
会引发另一个错误:invalid application of 'sizeof' to incomplete type 'Ui::SerialSetting'
isLarge = (sizeof(T)>sizeof(void*)),
最佳答案
您不能在前向声明的类(Q_DECLARE_METATYPE
)上调用Ui::SerialSetting
。另外,您需要声明信号用作参数的类型,在这种情况下为SerialSetting::Settings
。
更换
Q_DECLARE_METATYPE(Ui::SerialSetting)
与
Q_DECLARE_METATYPE(SerialSetting::Settings)
你应该没事的