2018-02-26 09:39:53 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
2023-04-06 09:23:37 +02:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2018-02-26 09:39:53 +01:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "Invoker.h"
|
2018-08-03 08:15:28 +02:00
|
|
|
|
2018-02-27 17:47:23 +01:00
|
|
|
#include <QCoreApplication>
|
2018-02-26 09:39:53 +01:00
|
|
|
#include <QDebug>
|
2018-03-02 11:26:25 +01:00
|
|
|
#include <QThread>
|
2018-08-03 08:15:28 +02:00
|
|
|
#include <QTimer>
|
2018-02-26 09:39:53 +01:00
|
|
|
|
2023-04-04 08:49:11 +02:00
|
|
|
static void debugNone1() { qDebug() << "None 1"; }
|
|
|
|
static void debugNone2() { qDebug() << "None 2"; }
|
|
|
|
static void debugValueI1( int i ) { qDebug() << "I1" << i; }
|
|
|
|
static void debugValueI2( int i ) { qDebug() << "I2" << i; }
|
|
|
|
static void debugValueD( qreal d ) { qDebug() << "D" << d; }
|
|
|
|
static void debugValue( qreal d, int i ) { qDebug() << d << i; }
|
2018-02-26 09:39:53 +01:00
|
|
|
|
|
|
|
class MyObject : public QObject
|
|
|
|
{
|
2018-03-02 14:58:43 +01:00
|
|
|
Q_OBJECT
|
|
|
|
|
2018-03-09 12:24:18 +01:00
|
|
|
Q_PROPERTY( int number WRITE setNumber )
|
|
|
|
Q_PROPERTY( qreal value WRITE setValue )
|
|
|
|
Q_PROPERTY( QString valueString WRITE setValueString )
|
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
public:
|
|
|
|
MyObject( QObject* parent = nullptr )
|
|
|
|
: QObject( parent )
|
2018-02-26 09:39:53 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-03-02 14:58:43 +01:00
|
|
|
Q_INVOKABLE void printInvokable( double d, int i ) const
|
|
|
|
{
|
|
|
|
qDebug() << "invokable" << d << i;
|
|
|
|
}
|
|
|
|
|
2018-03-09 12:24:18 +01:00
|
|
|
void setNumber( int number )
|
|
|
|
{
|
|
|
|
qDebug() << "setNumber" << number;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setValue( qreal value )
|
|
|
|
{
|
|
|
|
qDebug() << "setValue" << value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setValueString( const QString& s )
|
|
|
|
{
|
|
|
|
qDebug() << "setValueString" << s;
|
|
|
|
}
|
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
public Q_SLOTS:
|
2018-03-02 11:26:25 +01:00
|
|
|
void print0( double d, int i ) const
|
|
|
|
{
|
|
|
|
qDebug() << "print0" << d << i;
|
|
|
|
}
|
|
|
|
|
2018-02-26 09:39:53 +01:00
|
|
|
void print1( double d, int i ) const
|
|
|
|
{
|
2018-03-02 11:26:25 +01:00
|
|
|
qDebug() << "print1" << d << i;
|
2018-02-26 09:39:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void print2( int i, double d ) const
|
|
|
|
{
|
|
|
|
qDebug() << i << d;
|
|
|
|
}
|
|
|
|
|
|
|
|
void print3( double d ) const
|
|
|
|
{
|
|
|
|
qDebug() << d;
|
|
|
|
}
|
|
|
|
|
|
|
|
void print4( int i ) const
|
|
|
|
{
|
|
|
|
qDebug() << i;
|
|
|
|
}
|
2018-03-02 14:58:43 +01:00
|
|
|
|
|
|
|
void printS( const QString& s ) const
|
|
|
|
{
|
|
|
|
qDebug() << s;
|
|
|
|
}
|
2018-03-01 15:13:55 +01:00
|
|
|
};
|
|
|
|
|
2018-03-02 11:26:25 +01:00
|
|
|
static auto fs = []( int i, double d ) { qDebug() << i << d; };
|
|
|
|
|
2018-03-02 14:58:43 +01:00
|
|
|
class Application : public QCoreApplication
|
2018-03-01 15:13:55 +01:00
|
|
|
{
|
2018-08-03 08:15:28 +02:00
|
|
|
public:
|
|
|
|
Application( int& argc, char* argv[] )
|
|
|
|
: QCoreApplication( argc, argv )
|
|
|
|
, m_object( new MyObject() )
|
|
|
|
, m_thread( new QThread( this ) )
|
2018-03-01 15:13:55 +01:00
|
|
|
{
|
2018-03-02 14:58:43 +01:00
|
|
|
#if 1
|
2018-03-09 12:24:18 +01:00
|
|
|
m_invoker.addPropertyCall( m_object, "number" );
|
|
|
|
m_invoker.addPropertyCall( m_object, "value" );
|
|
|
|
m_invoker.addPropertyCall( m_object, "valueString" );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
m_invoker.addMethodCall( m_object, "print0(double,int)" );
|
|
|
|
m_invoker.addMethodCall( m_object, "print1(double,int)" );
|
2019-01-07 09:13:53 +01:00
|
|
|
m_invoker.addMethodCall( m_object, SLOT(print2(int,double)) );
|
2018-03-09 12:24:18 +01:00
|
|
|
m_invoker.addMethodCall( m_object, "print3(double)" );
|
|
|
|
m_invoker.addMethodCall( m_object, "print4(int)" );
|
|
|
|
m_invoker.addMethodCall( m_object, "print4(int)" );
|
|
|
|
m_invoker.addMethodCall( m_object, "printS(QString)" );
|
|
|
|
m_invoker.addMethodCall( m_object, "printInvokable(double,int)" );
|
2018-03-02 14:58:43 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
auto f = [this]( int i, double d ) { qDebug() << i << d << ( ++m_num ); };
|
2018-03-02 11:26:25 +01:00
|
|
|
|
2018-03-09 12:24:18 +01:00
|
|
|
m_invoker.addFunctionCall( m_object, &MyObject::print0 );
|
|
|
|
m_invoker.addFunctionCall( m_object, &MyObject::print1 );
|
|
|
|
m_invoker.addFunctionCall( QskMetaFunction() );
|
|
|
|
m_invoker.addFunctionCall( debugNone1 );
|
|
|
|
m_invoker.addFunctionCall( debugNone2 );
|
|
|
|
m_invoker.addFunctionCall( debugValue );
|
|
|
|
m_invoker.addFunctionCall( debugValueI1 );
|
|
|
|
m_invoker.addFunctionCall( debugValueI2 );
|
|
|
|
m_invoker.addFunctionCall( debugValueD );
|
|
|
|
m_invoker.addFunctionCall( m_object, &MyObject::print0 );
|
|
|
|
m_invoker.addFunctionCall( m_object, &MyObject::print1 );
|
|
|
|
m_invoker.addFunctionCall( m_object, &MyObject::print2 );
|
|
|
|
m_invoker.addFunctionCall( m_object, &MyObject::print3 );
|
|
|
|
m_invoker.addFunctionCall( m_object, &MyObject::print4 );
|
|
|
|
m_invoker.addFunctionCall( m_object, &MyObject::printS );
|
|
|
|
m_invoker.addFunctionCall( m_object, []( double d, int i ) { qDebug() << d << i; } );
|
|
|
|
|
|
|
|
m_invoker.addFunctionCall( m_object, f );
|
|
|
|
m_invoker.addFunctionCall( m_object, fs );
|
|
|
|
|
|
|
|
m_invoker.addFunctionCall( m_object, []( double d ) { qDebug() << d; } );
|
|
|
|
m_invoker.addFunctionCall( []() { qDebug() << "HERE"; } );
|
|
|
|
m_invoker.addFunctionCall( []( int i, double d ) { qDebug() << i << d; } );
|
|
|
|
m_invoker.addFunctionCall( []( int i ) { qDebug() << "I1" << i; } );
|
|
|
|
m_invoker.addFunctionCall( []( int i ) { qDebug() << "I2" << i; } );
|
|
|
|
m_invoker.addFunctionCall( []( double d ) { qDebug() << "V" << d; } );
|
|
|
|
m_invoker.addFunctionCall( []( const double& d ) { qDebug() << "R" << d; } );
|
2018-03-02 14:58:43 +01:00
|
|
|
#endif
|
2018-03-01 15:13:55 +01:00
|
|
|
}
|
|
|
|
|
2023-04-04 08:49:11 +02:00
|
|
|
~Application() override
|
2018-03-01 15:13:55 +01:00
|
|
|
{
|
2018-03-02 11:26:25 +01:00
|
|
|
delete m_object;
|
2018-03-01 15:13:55 +01:00
|
|
|
}
|
|
|
|
|
2018-03-02 11:26:25 +01:00
|
|
|
void invokeDirect()
|
2018-03-01 15:13:55 +01:00
|
|
|
{
|
2018-03-02 11:26:25 +01:00
|
|
|
qDebug() << "== Direct Connections";
|
|
|
|
m_invoker.invoke( 3.14, 35, Qt::DirectConnection );
|
2018-03-01 15:13:55 +01:00
|
|
|
}
|
2018-02-26 09:39:53 +01:00
|
|
|
|
2018-03-02 11:26:25 +01:00
|
|
|
void invokeQueued()
|
|
|
|
{
|
|
|
|
qDebug() << "== Queued Connections";
|
|
|
|
m_invoker.invoke( 0.07, 42, Qt::QueuedConnection );
|
|
|
|
}
|
|
|
|
|
|
|
|
void invokeBlockingQueued()
|
|
|
|
{
|
|
|
|
m_thread->start();
|
2018-03-02 14:58:43 +01:00
|
|
|
|
2018-03-02 11:26:25 +01:00
|
|
|
m_object->moveToThread( m_thread );
|
|
|
|
|
|
|
|
qDebug() << "== Blocking Queued Connections";
|
|
|
|
m_invoker.invoke( 0.54, 88, Qt::BlockingQueuedConnection );
|
|
|
|
|
|
|
|
QTimer::singleShot( 10, m_thread, &QThread::quit );
|
|
|
|
}
|
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
private:
|
2018-03-02 11:26:25 +01:00
|
|
|
Invoker m_invoker;
|
|
|
|
MyObject* m_object;
|
|
|
|
QThread* m_thread;
|
|
|
|
|
|
|
|
int m_num = 111;
|
|
|
|
};
|
2018-03-01 15:13:55 +01:00
|
|
|
|
2018-02-26 09:39:53 +01:00
|
|
|
int main( int argc, char* argv[] )
|
|
|
|
{
|
2018-03-02 11:26:25 +01:00
|
|
|
Application app( argc, argv );
|
|
|
|
|
|
|
|
app.invokeDirect();
|
|
|
|
|
|
|
|
QTimer::singleShot( 0, &app, &Application::invokeQueued );
|
|
|
|
QTimer::singleShot( 20, &app, &Application::invokeBlockingQueued );
|
|
|
|
|
|
|
|
QTimer::singleShot( 50, &app, QCoreApplication::quit );
|
2018-03-01 15:13:55 +01:00
|
|
|
|
2018-02-27 17:47:23 +01:00
|
|
|
return app.exec();
|
2018-02-26 09:39:53 +01:00
|
|
|
}
|
2018-03-02 14:58:43 +01:00
|
|
|
|
|
|
|
#include "main.moc"
|