150 lines
3.2 KiB
C++
Raw Normal View History

2018-02-26 09:39:53 +01:00
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#include "Invoker.h"
#include <QCoreApplication>
2018-02-26 09:39:53 +01:00
#include <QDebug>
#include <QTimer>
2018-02-26 09:39:53 +01:00
2018-03-02 07:07:19 +01:00
static void debugNone1()
2018-03-02 06:57:08 +01:00
{
2018-03-02 07:07:19 +01:00
qDebug() << "None 1";
}
static void debugNone2()
{
qDebug() << "None 2";
2018-03-02 06:57:08 +01:00
}
2018-03-02 07:23:12 +01:00
static void debugValueI1( int i )
2018-02-26 09:39:53 +01:00
{
2018-03-02 07:23:12 +01:00
qDebug() << "I1" << i;
}
static void debugValueI2( int i )
{
qDebug() << "I2" << i;
2018-02-26 09:39:53 +01:00
}
2018-03-02 06:57:08 +01:00
static void debugValueD( qreal d )
{
2018-03-02 07:23:12 +01:00
qDebug() << "D" << d;
2018-03-02 06:57:08 +01:00
}
2018-02-26 09:39:53 +01:00
static void debugValue( qreal d, int i )
{
qDebug() << d << i;
}
class MyObject : public QObject
{
Q_OBJECT
2018-02-26 09:39:53 +01:00
public:
MyObject( QObject* parent = nullptr ):
QObject( parent )
{
}
void print1( double d, int i ) const
{
qDebug() << d << i;
}
void print2( int i, double d ) const
{
qDebug() << i << d;
}
void print3( double d ) const
{
qDebug() << d;
}
void print4( int i ) const
{
qDebug() << i;
}
Q_SIGNALS:
void done( double, int );
};
class MyObject2: public MyObject
{
public:
MyObject2( QObject* parent = nullptr ):
MyObject( parent )
{
}
virtual ~MyObject2()
{
}
virtual void noop()
{
}
2018-02-26 09:39:53 +01:00
};
static auto fs = []( int i, double d ) { qDebug() << i << d; };
2018-02-26 09:39:53 +01:00
int main( int argc, char* argv[] )
{
QCoreApplication app( argc, argv );
2018-02-26 09:39:53 +01:00
MyObject object;
MyObject2 object2;
2018-02-26 09:39:53 +01:00
2018-03-01 17:11:59 +01:00
int num = 111;
auto f = [&num]( int i, double d ) { qDebug() << i << d << (++num); };
2018-02-26 09:39:53 +01:00
Invoker invoker;
#if 1
2018-03-01 17:11:59 +01:00
invoker.addCallback( QskMetaFunction() );
2018-03-02 07:07:19 +01:00
invoker.addCallback( debugNone1 );
invoker.addCallback( debugNone2 );
2018-02-26 09:39:53 +01:00
invoker.addCallback( debugValue );
2018-03-02 07:23:12 +01:00
invoker.addCallback( debugValueI1 );
invoker.addCallback( debugValueI2 );
2018-03-02 06:57:08 +01:00
invoker.addCallback( debugValueD );
2018-02-26 09:39:53 +01:00
invoker.addCallback( &object, &MyObject::print1 );
invoker.addCallback( &object2, &MyObject2::print1 );
2018-02-26 09:39:53 +01:00
invoker.addCallback( &object, &MyObject::print2 );
invoker.addCallback( &object, &MyObject::print3 );
invoker.addCallback( &object, &MyObject::print4 );
invoker.addCallback( &object, []( double d, int i ) { qDebug() << d << i; } );
invoker.addCallback( &object, f );
invoker.addCallback( &object2, f );
invoker.addCallback( &object, fs );
invoker.addCallback( &object2, fs );
2018-02-26 09:39:53 +01:00
invoker.addCallback( &object, []( double d ) { qDebug() << d; } );
invoker.addCallback( []() { qDebug() << "HERE"; } );
invoker.addCallback( []( int i, double d ) { qDebug() << i << d; } );
2018-03-02 07:23:12 +01:00
invoker.addCallback( []( int i ) { qDebug() << "I1" << i; } );
invoker.addCallback( []( int i ) { qDebug() << "I2" << i; } );
2018-02-26 09:39:53 +01:00
invoker.addCallback( []( double d ) { qDebug() << d; } );
#endif
2018-02-26 09:39:53 +01:00
#if 1
qDebug() << "== Direct Connections";
invoker.invoke( 3.14, 35, Qt::DirectConnection );
2018-03-01 17:11:59 +01:00
qDebug() << "\n\n== Queued Connections";
QTimer::singleShot( 0,
[&invoker] { invoker.invoke( 0.07, 42, Qt::QueuedConnection ); } );
#endif
QTimer::singleShot( 100, &app, QCoreApplication::quit );
return app.exec();
2018-02-26 09:39:53 +01:00
}
#include "main.moc"