如何将Singleton类信号连接到MainWindow类插槽或方法
How can I connect singleton class signals to mainwindow class slot or method
我拥有一个串行通信类,并且由于数据接收到结束,我想在获得赞誉时发送信号。由于此信号,我正在调用图形方法。建立了连接,但是接收插槽不听信号。
singleton类:
class SerialCommunication : public QObject{
Q_OBJECT public:
static SerialCommunication & GetInstance() ;
....
QVector<double> ReadDataVector ;
私人:
SerialCommunication() ;
static SerialCommunication * Instance ;
QList<QSerialPortInfo> PortList ;
bool IsOpen = false ; ....
私人老虎机: void readdata((;
信号: void dataisdone((;
};
接收数据插槽:
void SerialCommunication::ReceivedData()
{ ...
for(;true;)
{
....
switch (Commend) {
case Data_Reply:
qDebug()<<"Data Reply" ;
AppendToUint16Vector(ReadDataVector,Package);
break;
case Data_Reply_Done:
qDebug()<<" Data_Reply_Done" ;
MsgBox.information(0,"Transfer information. ","The data transfer is complete n Please click draw button.");
emit SerialCommunication::GetInstance().DataIsDone();
break;
default:
ClearBuffer();
qDebug()<<" default" ;
break;
}}}
和连接在这里
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(&SerialCommunication::GetInstance(),SIGNAL(SerialCommunication::DataIsDone),this,SLOT( GraficSetupAndInit()));
SetupUI();
}
qobject ::连接:预期的括号,信号serialCommunication :: serialCommunication :: dataisdone in .. muteferrika mainwindow.cpp:10Qobject :: Connect :(接收器名称:'MainWindow'(
使用旧的Qt4
语法您的connect
呼叫应该是...
connect(&SerialCommunication::GetInstance(), SIGNAL(DataIsDone()),
this, SLOT(GraficSetupAndInit()));
说您确实应该使用Qt5
可用的较新的信号插槽语法。具体...
connect(&SerialCommunication::GetInstance(), &SerialCommunication::DataIsDone,
this, &MainWindow::GraficSetupAndInit);
相关文章:
- 如何将点击的信号和插槽添加到qt中的自定义按钮中
- 如何在没有信号的情况下从C++执行QML插槽
- 从Q_INVOKABLE功能或插槽中更改QQuick图像源
- 升压信号2将插槽传递到成员功能以断开连接
- 如何在qt中将信号和插槽与另一个对象连接 --解决了
- C++ 信号和插槽不工作:插槽不响应事件
- NS3 插槽混淆(需要帮助理解)
- QObject::连接无法将信号连接到*this*对象的插槽
- QT 插槽未在主线程上调用
- 通过插槽和信号在不同线程中的两个qt对象之间进行通信
- 控制带有信号/插槽的Qt QML滑动视图
- Qt 信号/插槽问题
- QT5 信号不会激活插槽内的功能
- Qt5:连接:如果插槽的参数少于信号,如何使用"连接"
- 需要实例化不同类/对象并在启动时确定的硬件插槽的设计模式
- Qt信号和插槽如果从QRunnable或其他线程调用,则不起作用
- Qt插槽调用了两次
- C++Qt信号和插槽
- 如何将Singleton类信号连接到MainWindow类插槽或方法
- Qt:使用信号和插槽从另一个类调用MainWindow::Ui