#include <QtCore>
#include <QtSql>
{
Q_OBJECT
public:
Client();
~Client();
public slots:
void start();
signals:
void done();
}; // Client
Client::Client()
{
}
Client::~Client()
{
}
void Client::start()
{
// we could do some work here, but for the test simply remove the connection
emit done();
}
int main(int argc, char* argv[])
{
Client client;
client.moveToThread(&t);
QObject::connect(&t,
SIGNAL(started
()),
&client,
SLOT(start
()));
QObject::connect(&client,
SIGNAL(done
()),
&t,
SLOT(quit
()));
QObject::connect(&t,
SIGNAL(finished
()),
&app,
SLOT(quit
()));
t.start();
return app.exec();
}
#include "main.moc"
#include <QtCore>
#include <QtSql>
class Client: public QObject
{
Q_OBJECT
public:
Client();
~Client();
public slots:
void start();
signals:
void done();
}; // Client
Client::Client()
{
QSqlDatabase::addDatabase("QMYSQL", "my_connection");
}
Client::~Client()
{
}
void Client::start()
{
// we could do some work here, but for the test simply remove the connection
QSqlDatabase::removeDatabase("my_connection");
emit done();
}
int main(int argc, char* argv[])
{
QCoreApplication app(argc, argv);
QThread t;
Client client;
client.moveToThread(&t);
QObject::connect(&t, SIGNAL(started()), &client, SLOT(start()));
QObject::connect(&client, SIGNAL(done()), &t, SLOT(quit()));
QObject::connect(&t, SIGNAL(finished()), &app, SLOT(quit()));
t.start();
return app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
Bookmarks