Public Slots | Signals | Public Member Functions | Protected Member Functions

QueryThread Class Reference

This is the thread in which QueryWorker works. More...

#include <querythread.h>

Inheritance diagram for QueryThread:
Inheritance graph
[legend]
Collaboration diagram for QueryThread:
Collaboration graph
[legend]

List of all members.

Public Slots

bool cancelQuery ()
void slot_queryQueue_changed (QueryQueue *queue)

Signals

void querying (bool)
void signal_result (QueryThreadCommand result)
void fwdToWorker (QueryQueue *queue)

Public Member Functions

 QueryThread (QueryThreadConnSpecs &specs, QueryQueue *queue, QObject *parent=0)
 ~QueryThread ()
void waitToStart ()
QueryThreadCommand currentCmd ()

Protected Member Functions

void run ()

Detailed Description

This is the thread in which QueryWorker works.


Constructor & Destructor Documentation

QueryThread::QueryThread ( QueryThreadConnSpecs specs,
QueryQueue queue,
QObject parent = 0 
)

                                                                                                  : QThread(parent)
{
    this->specs = specs;
    this->m_queryQueue = queue;
}

QueryThread::~QueryThread (  ) 

{
    Q_ASSERT(worker);
    delete worker;
};


Member Function Documentation

bool QueryThread::cancelQuery (  )  [slot]

{
    Q_ASSERT(QSqlDatabase::database("ThreadConnection", false).driverName() == "QPSQL");
    QSqlDriver *drv = QSqlDatabase::database("ThreadConnection", false).driver();
    Q_ASSERT(drv);
    //According to the Postgres documentation, this is ThreadSafe
    PGcancel *cancel = PQgetCancel(drv->handle().value<PGconn*>());
    Q_ASSERT(cancel);
    char *errMsg = NULL;
    bool cancelSuccess = (bool) PQcancel(cancel, errMsg, 256); //1 = success, 0 = failure
    if (!cancelSuccess) qDebug() << "Canceling connection returned: " << errMsg;
    return cancelSuccess;
}

QueryThreadCommand QueryThread::currentCmd (  ) 

Referenced by Database::execPending().

{
    return worker->currentCmd();
}

void QueryThread::fwdToWorker ( QueryQueue queue  )  [signal]

Referenced by run(), and slot_queryQueue_changed().

void QueryThread::querying ( bool   )  [signal]

Referenced by run().

void QueryThread::run (  )  [protected]

Reimplemented from QThread.

{
    qDebug() << "QueryThread starting, one moment please..." ;

    // Create worker object within the context of the new thread
    worker = new QueryWorker(specs, m_queryQueue);

    connect(this, SIGNAL(fwdToWorker(QueryQueue*)),
            worker, SLOT(slotExecute(QueryQueue*)));

    // Critical: register new type so that this signal can be
    // dispatched across thread boundaries by Qt using the event
    // system
    qRegisterMetaType<QueryThreadCommand>("QueryThreadCommand");

    // forward final signal
    connect(worker, SIGNAL(signal_result(QueryThreadCommand)),
            this, SIGNAL(signal_result(QueryThreadCommand)));

    connect(worker, SIGNAL(querying(bool)),
            this, SIGNAL(querying(bool)));

    qDebug() << "QueryThread started.";
    exec();  // our event loop
}

void QueryThread::signal_result ( QueryThreadCommand  result  )  [signal]

Referenced by run().

void QueryThread::slot_queryQueue_changed ( QueryQueue queue  )  [slot]

{
    emit fwdToWorker(queue);
}

void QueryThread::waitToStart (  ) 

{
    //Currently not necessary
    //...
}


The documentation for this class was generated from the following files: