View this PageEdit this PageUploads to this PageVersions of this PageHomeRecent ChangesSearchHelp Guide

Snippets de código C++11 para Qt5




Monday, 17 October 2016, 9:53:26 am
Uso de lambdas con signals/slots Es este post

#include <QCoreApplication>
#include <QDebug>
#include <QObject>
#include <QTimer>

void freeFunction() {
    qDebug() << "free function";
}

static void staticFunction() {
    qDebug() << "static function";
}

int main(int argc, char *argv[]) {
    QCoreApplication app(argc, argv);

    QTimer timer;
    timer.setInterval(500);

    QObject::connect(&timer, &QTimer::timeout, staticFunction);
    QObject::connect(&timer, &QTimer::timeout, freeFunction);
    QObject::connect(&timer, &QTimer::timeout, []() { qDebug() << "lambda"; });

    timer.start();

    return app.exec();
}