[Interest] QSqlQuery
Igor Mironchik
igor.mironchik at gmail.com
Sun Jan 26 21:22:31 CET 2014
> Hi Igor,
>
> On 26-Jan-14 4:29 PM, Igor Mironchik wrote:
>> I have some questions about database support in Qt 5.
>>
>> First of all, is it safe to transfer a QSqlQuery instance from one
>> thread to another to process him in another thread. I.e. I want to
>> execute SELECT query on "DB" thread and return a QSqlQuery from that
>> thread to the GUI thread, where I will navigate and show users the
>> result of the query.
> Hmm, why do you want to return the Query to the GUI thread? Update the
> Model from the thread executing the Query and let QT take care of the GUI.
The question is opened still. The simplest QSqlQueryModel stores
QSqlQuery and work with it.
Look:
QVariant QSqlQueryModel::data(const QModelIndex &item, int role) const
{
Q_D(const QSqlQueryModel);
if (!item.isValid())
return QVariant();
QVariant v;
if (role & ~(Qt::DisplayRole | Qt::EditRole))
return v;
if (!d->rec.isGenerated(item.column()))
return v;
QModelIndex dItem = indexInQuery(item);
if (dItem.row() > d->bottom.row())
const_cast<QSqlQueryModelPrivate *>(d)->prefetch(dItem.row());
if (!d->query.seek(dItem.row())) {
d->error = d->query.lastError();
return v;
}
return d->query.value(dItem.column());
}
And my question: is it safe to use QSqlQuery, not QSqlDatabase in
another thread?
--
Best Regards,
Igor Mironchik.
More information about the Interest
mailing list