[Interest] Unique Database connection name

Karl Ruetz karl.ruetz at ruetzdogz.com
Wed Sep 4 18:50:23 CEST 2013


 

On 2013-09-04 10:23, arno wrote: 

> Hello all,
> 
> Problem:
>
Generate a unique database connection name for a connection in a
Thread
> (QRunnable). I'm trying to do this (pseudo code):
> 
> class
LongRunning : public QObject, public QRunnable {
> Q_OBJECT
> explicit
LongRunning();
> 
> protected:
> virtual void run()
> }
> 
> void
LongRunning::run() {
> //mydb is set up in a singleton
> QSqlDatabase db
= QSqlDatabase::cloneDatabase("mydb", uniquesting);
> ... select
something from database...
> End of LongRunning:
>
QSqlDatabase::removeDatabase(uniquestring);
> }
> 
> LongRunning is
managed by a QThreadPool. I'm looking for a way to
> generate a unique
"uniquestring" for each connection.
> 
> I tried
QString::number(qint64(this)) as "uniqestring", but of course it
>
doesn't work, because "this" is reused by QThreadPool, and it's so
ugly
> that it hurts the eye.
> 
> I tried QUuid, but the documentation
is scarce. Seems it's only a class
> for representing a UUID, not for
generating one, right?
> 
> Anything obvious I missed?

Any chance you
can use a default connection for the application rather than create an
connection in each thread? 

Karl 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130904/6fd43f94/attachment.html>


More information about the Interest mailing list