Umm, wait, why would I ask you for help if I considered you stupid? I forgot to remove the SignalClass from that part of the code because I was editing my copy paste from my previous post and overlooked that part. Obviously this is not the exact code I have, there are lots of variable definitions, array populating, my project specific code (which I am forbidden to post for confidentiality reasons) etc which don't belong to the ambit of this problem and thus I did not include here (for starters, my QueryAction header class is 8 lines long, in reality it is around 35~40 lines.) Fo example after the querying is complete I have the action class emit a signal which feeds in to a slot in the view that shows a message like 'Total number of query results is <some_number>', but I did not include it here because it doesn't add anything to the problem scope. I have changed some of my variable names here so that I had to do less typing (for example I renamed fSearchAction to action). It's only after you said that the Signal Class mapper might be causing the problem did I go ahead and change it (while editing I forgot to edit one part). In essence this is the summary of the entire process I am currently running. Why on earth would I not try out what you are suggesting and yet ask you for further suggestions?
If it helps, here is my latest code (statutory disclaimer: this code cannot be and is not considered completely representative of my entire project, not does it purport to be. It's aim is to provide a high level overview of my problem, and is open to request [please] for more information, that will be provided subject to the terms and conditions of the company I am working for in capacity of a software engineer to make a product, with an ardent expectation that it will be sufficient to experienced Qt programmers in this forum to be able to offer advice and suggestion to improve it. Viewers' discretion is advised.)
QueryView.hpp:
class QueryView
{
QueryAction *action;
signals:
void excuteSignal();
void stopExistingQuery();
}
class QueryView
{
QThread *t;
QueryAction *action;
signals:
void excuteSignal();
void stopExistingQuery();
}
To copy to clipboard, switch view to plain text mode
QueryView.cpp:
QueryView::QueryView()
{
connect(queryButton, SIGNAL(clicked()),this, SLOT(doQuery()));
}
void QueryView::doQuery()
{
emit stopExistingQuery();
action = new QueryAction(queryTerm);
connect(this,SIGNAL(excuteSignal()), action, SLOT(startQuery()));
connect(this,SIGNAL(stopExistingQuery()), action, SLOT(stopQuery()));
connect(action,
SIGNAL(updateViewSignal
(QString)),
this,
SLOT(updateView
(QString)));
action->moveToThread(t);
t->start();
emit excuteSignal();
}
QueryView
::updateView(QString term
){
...
update view with query result, currently a string
for testing purpose, as a
QPushButton, forming a series of buttons in a
QTableWidget}
QueryView::QueryView()
{
connect(queryButton, SIGNAL(clicked()),this, SLOT(doQuery()));
}
void QueryView::doQuery()
{
t = new QThread()
emit stopExistingQuery();
action = new QueryAction(queryTerm);
connect(this,SIGNAL(excuteSignal()), action, SLOT(startQuery()));
connect(this,SIGNAL(stopExistingQuery()), action, SLOT(stopQuery()));
connect(action, SIGNAL(updateViewSignal(QString)),this, SLOT(updateView(QString)));
action->moveToThread(t);
t->start();
emit excuteSignal();
}
QueryView::updateView(QString term)
{
...update view with query result, currently a string for testing purpose, as a QPushButton, forming a series of buttons in a QTableWidget
}
To copy to clipboard, switch view to plain text mode
QueryAction.hpp:
class QueryAction
{
signals:
}
class QueryAction
{
QMutex m_mutex;
signals:
void updateViewSignal(QString);
}
To copy to clipboard, switch view to plain text mode
QueryAction.cpp:
QueryAction::QueryAction(QueryTerm& queryTerm): fQueryTerm(queryTerm)
{
continueQuery = true;
}
void QueryAction::startQuery()
{
//init cursor
while (db_cursor != empty)
{
...get query result
if (continueQuery)
emit updateViewSignal(aResult.asQString());
else
break;
}
}
void QueryAction::stopQuery()
{
continueQuery = false;
}
QueryAction::QueryAction(QueryTerm& queryTerm): fQueryTerm(queryTerm)
{
QMutexLocker locker(&m_mutex);
continueQuery = true;
}
void QueryAction::startQuery()
{
//init cursor
while (db_cursor != empty)
{
...get query result
QMutexLocker locker(&m_mutex);
if (continueQuery)
emit updateViewSignal(aResult.asQString());
else
break;
}
}
void QueryAction::stopQuery()
{
QMutexLocker locker(&m_mutex);
continueQuery = false;
}
To copy to clipboard, switch view to plain text mode
Bookmarks