gpt4 book ai didi

c++ - 在连接信号/槽中使用 C++ 关键字

转载 作者:行者123 更新时间:2023-11-30 01:39:08 24 4
gpt4 key购买 nike

在 Qt 5.9 中,我尝试使用 C++ 关键字代替 SLOT。这可能吗(没有单独的方法)?

类似于:

QObject::connect(&timer, SIGNAL(timeout()),  this, (delete image_ptr));

那是行不通的,在我的代码示例下面:

QImage *image_ptr = new QImage(3, 3, QImage::Format_Indexed8);
QEventLoop evt;
QFutureWatcher<QString> watcher;
QTimer timer(this);
timer.setSingleShot(true);
QObject::connect(&watcher, &QFutureWatcher<QString>::finished, &evt, &QEventLoop::quit);
QObject::connect(&timer, SIGNAL(timeout()), &watcher, SLOT(cancel()));
QObject::connect(&timer, SIGNAL(timeout()), &evt, SLOT(quit));
QObject::connect(&timer, SIGNAL(timeout()), this, (delete image_ptr));
QFuture<QString> future = QtConcurrent::run(this,&myClass::myMethod,*image_ptr);
watcher.setFuture(future);
timer.start(100);
evt.exec();

最佳答案

连接示例中的 lambda 表达式:

connect(
sender, &Sender::valueChanged,
[=]( const QString &newValue ) { receiver->updateValue( "senderValue", newValue ); }
);

关于c++ - 在连接信号/槽中使用 C++ 关键字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46411418/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com