Skip to content
  • 0 Votes
    14 Posts
    6k Views
    KroMignonK
    @davidesalvetti Hmm, I am not very confident in your solution. I would create a helper class to create/use right connection according to current thread. Something like this (it is just a skeleton, not sure it is working as it is): #include <QSqlDatabase> #include <QThread> class MyBDConnection { QString m_dbPath; QString m_dbName; Q_DISABLE_COPY(MyBDConnection) public: explicit MyBDConnection(const QString &sqlitePath, const QString &cnxName): m_dbPath(sqlitePath), m_dbName(cnxName) {} QSqlDatabase getDBConnection() { // Starting with Qt 5.11, sharing the same connection between threads is not allowed. // Use a dedicated connection for each thread requiring access to the database, // using the thread address as connection name. QSqlDatabase cnx; QString dbName = QStringLiteral("%1_%2").arg(m_dbName).arg(qintptr(QThread::currentThreadId()), 0, 16); if(QSqlDatabase::contains(dbName)) { cnx = QSqlDatabase::database(dbName); } else { cnx = QSqlDatabase::addDatabase(QStringLiteral("QSQLITE"), dbName); cnx.setDatabaseName(m_dbPath); if (!cnx.isValid() || !cnx.open()) { qDebug() << "DB connection creation error!"; } } return cnx; } } And the only create on instance of this class and pass the pointer to each class which need connection to DB.
  • Multi-thread GUI execution

    Unsolved General and Desktop gui thread multithreads executable
    7
    0 Votes
    7 Posts
    2k Views
    jsulmJ
    @sebs What I don't understand: you want an application with 3 threads, right? But why do you create new process?
  • How to run a thread again?

    Unsolved General and Desktop thread ui object threading threads
    4
    0 Votes
    4 Posts
    3k Views
    SGaistS
    Hi, The terminate as it names suggest kills the the thread so it's state is not guaranteed as mentioned in the documentation. Not that you are automagically destroying everything once your operation is done. See your connections to the deleteLater slots.
  • Terminate QThread correctly

    Unsolved General and Desktop thread qt4.8 yocto dizzy
    11
    0 Votes
    11 Posts
    19k Views
    BuckwheatB
    Hi @Andrea WOW! Infinite loop to just sleep and process events. Why not just start a timer of PreciseTimer and allow the events to flow freely in the thread? Since you want it to run as fast as possible you can even set the timeout to 0 to run freely when there are no events. You can then look at thread->requestInterruption () and the thread will comply! Just make sure if you are doing something in a loop in the timer callback you check thread ()->isInterruptionRequested (). And best of all... NO CHECKING THE EVENT QUEUE! There is a nice writeup about proper thread use at: https://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/ You are basically there with your code. Just the loop is wasteful.
  • 0 Votes
    3 Posts
    1k Views
    D
    @SGaist Thank you for your answer!
  • 0 Votes
    2 Posts
    1k Views
    SGaistS
    Hi and welcome to devnet, You can use a proxy model that adds the columns you want/need. You can keep updating the DB content and trigger the GUI update at some known interval or when a certains amount of changed happened to the database.
  • 0 Votes
    8 Posts
    7k Views
    F
    Ok, thanks, I think I have all information I need now.
  • 0 Votes
    1 Posts
    983 Views
    No one has replied
  • About Qt::DirectConnection

    Unsolved General and Desktop thread connect movetothread
    7
    0 Votes
    7 Posts
    7k Views
    jsulmJ
    @diverger As @micland already explained this does not have anything to do with Qt. It is a general problem with multi-threading: if you call a method from an object which leaves in another thread then you have to make sure this does not cause any problems.
  • Return value from slot in differnet thread

    Unsolved General and Desktop return value slot thread
    12
    0 Votes
    12 Posts
    12k Views
    McLionM
    @VRonin Thanks for your input - there seem to be some misunderstanding. I can not and do not want to wait for the acknowledge of the server as a trigger to sent the next log message - this is against the idea. Log messages need always to be sent, regardless wether the server acknowledges or not - imagine the server even does not acknowledge. Every message sent has an ID# that is incremented by one for every new log message sent. The server acknowledges every message with returning the ID#. Looking at the network of the server with Wireshark and having incoming log messages with time stamps of the same msec - obviously the server has no time to send the acknowledge between incoming protocols. I.e. Sending #1 and # 2 in such a short sequence, obviously when sending #2 the counter for a missed message goes up to one. This is inherit by this system and is by design. Therefore, I'm going to implement a gap of at least a few msec between sending messages. Because the messages are all handled and forwarded in the application by signals / QtEvent queues, I dont have a solid idea so far how to do this. I may have to create a time gated sending queue before handing the messages over to the signal and the QtEvent queue.
  • 0 Votes
    3 Posts
    2k Views
    eKKiME
    Yes i did. And with that clue i figured it out! QApplication::desktop()->screenGeometry(screenIndex); works like a charm. Tyvm!
  • readyRead of a socket in a seperate thread

    Unsolved General and Desktop socket thread readyread
    6
    0 Votes
    6 Posts
    4k Views
    McLionM
    @VRonin Server is on a different machine in the LAN and the software is not from me. I only implement the client side.
  • 0 Votes
    5 Posts
    4k Views
    O
    @SGaist said: mkspecs/device/linux-rasp-pi2-g++ Shouldn't it maybe be mkspecs/device/linux-rasp-pi-g++ (without the 2)? In his makefile there is this line: INCPATH = -I../threadtest -I. -I/usr/local/qt5/mkspecs/devices/linux-rasp-pi-g++
  • 0 Votes
    2 Posts
    973 Views
    SGaistS
    Hi, What about doing the subscription related stuff in your proxy ? Basically two methods: FeedProxy::subscribe(YouCoolClass *) FeedProxy::unsubscribe(YouCoolClass *) No need for any special detection and you know exactly where things are happening.
  • Internal data exchange through threads with topic

    Unsolved Brainstorm signal & slot qthread thread
    1
    0 Votes
    1 Posts
    705 Views
    No one has replied
  • Improving drawing/painting performance

    Solved General and Desktop paint draw thread
    12
    0 Votes
    12 Posts
    11k Views
    kshegunovK
    @SysTech Thanks again! You're very welcome. Those 3D displays are kind of handy for visualizing the radio output but they are right now pretty CPU intensive. If I may insert yet another suggestion here. While I don't believe you'd gain much by using OpenGL painting for the "waterfall" data, I think switching to it for the 3D displays would work better. I nice side effect would be that you can also render OpenGL from different threads, provided the appropriate locking mechanisms are in place. You could, as the most simple test, try using QOpenGLWidget for those FFT displays. Kind regards.
  • 0 Votes
    13 Posts
    6k Views
    LeeiL
    @SGaist I don't mind refactoring it, it's not very long. I will definitely look into this. Thanks!
  • Doc > Qt 4.8 > Mandelbrot Example

    Unsolved General and Desktop docs documentation thread syncronization
    10
    0 Votes
    10 Posts
    4k Views
    SGaistS
    You're welcome ! Since it's all clear now, please mark the thread as solved using the "Topic Tool" button so that other forum users may know an answer has been found :)
  • 0 Votes
    11 Posts
    7k Views
    kshegunovK
    @zzaj No problem. Good luck with your project!!
  • QScriptEngine in a thread

    Unsolved General and Desktop qscriptengine thread
    2
    0 Votes
    2 Posts
    1k Views
    SGaistS
    Hi, I haven't used that class but from the looks of it, using the worker object approach should be fine.