我不知道这是怎么回事。我想将一个类的值传递给另一个。这是代码:
主窗口
public slots:
void printNumbers(int);
主窗口
void MainWindow::printNumbers(int a)
{
qDebug() << a;
}
myudp.h
signals:
inline void sendBuff(int);
myudp.cpp
[***]
MainWindow *widget = new MainWindow();
connect(socket, SIGNAL(readyRead()), this, SLOT(readyRead()));
const bool connected = connect(this , SIGNAL(sendBuff(int)), widget ,SLOT(printNumbers(int)));
qDebug() << "Connection established?" << connected;
[***]
void MyUDP::readyRead()
{
// when data comes in
emit sendBuff(13);
[***]
}
inline void MyUDP::sendBuff(int a)
{
qDebug() << "sending " << a ;
}
Main.cpp
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMainWindow window;
MainWindow *widget = new MainWindow();
window.setCentralWidget(widget);
window.resize(900, 600);
window.show();
MyUDP *client = new MyUDP();
return a.exec();
}
由于出现错误,我使用了“内联”:复制MyUDP :: sendBuff(int a)。
我不知道这是否是一个问题。
当我执行“ send sendBuff(12) ”时,我只收到“ sending 12 ”,即使变量“ connected ”为true ,我也没有捕获到printNumbers()的输出。
删除插槽的内联声明,如果您的类需要sendBuff内部使用,则为此声明一个新方法...
signals:
void sendBuffSignal(int);
并在cpp中
void MyUDP::sendBuff(int a)
{
qDebug() << "sending " << a ;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句