Results 1 to 2 of 2

Thread: Advice using sqlite3 with threading

  1. #1
    Join Date
    Dec 2010
    Posts
    55
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Advice using sqlite3 with threading

    The program is a GUI job manager to give an interface to allow the user to setup a job queue, and monitor the status of what is running.
    I am using a database to store job parameters and results of jobs.
    There is a separate module which allows me to actually send commands to start jobs and get data back.

    Since I do not want the GUI to be frozen while jobs are running I have worker thread which is used to do all the work of sending out jobs, getting data, and storing it in a database.

    ANYWAYS, here is my problem. I was using mysqldb and it was working fine, however, I decided to switch to sqlite3. However, when I try to execute a db command from my worker thread, I get the following errors:

    QObject::setParent: New parent must be in the same thread as the previous parent
    QFont: It is not safe to use text and fonts outside the GUI thread

    1. Is using a thread a good way to implement what I am trying to do? I cannot think of another way to allow jobs to run (monitor the status) without having the GUI frozen.
    2. How can I use sqlite3 within my worker thread? What would be the best approach here?

    Thanks

    Here are some Python Code excerpts:

    def store_job(db, results)
    db.execute("INSERT INTO `results` name values ?", results)

    def process_job(client):
    job_status = "Running Job"
    client.start_job()

    def run_jobs_thread():
    client = job_module(jobid) ### job interface instance
    process_job(client)
    del client
    job_status = "Storing Data"
    if running:
    store_job(db_cursor,client.results)
    job_status = "Complete"

    def update_job_status():
    if jobt.isRunning():
    mw.joblist.item(jobid,3).setText(job_status)

    def monitor_log():
    ###check some stuff and update running variable

    class jobs(QThread):
    def run(self):
    run_jobs_thread()

    def init_form()
    jobt = jobs(app)
    timer = QTimer(app)
    timer2 = QTimer(app)
    QObject.connect(timer, QtCore.SIGNAL("timeout()"), update_job_status)
    QObject.connect(timer2, QtCore.SIGNAL("timeout()"), monitor_status)
    timer.start(1000)
    timer2.start(2000)
    running = False
    Last edited by enricong; 22nd December 2010 at 20:40.
    Running:
    RHEL 5.4
    Python 2.7.2
    Qt 4.7.4
    SIP 4.7.8
    PyQt 4.7

  2. #2
    Join Date
    Jan 2009
    Location
    The Netherlands and Spain
    Posts
    150
    Thanks
    6
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Advice using sqlite3 with threading

    To avoid multiple threads with time-consuming processes you can also call QApplication:: processEvents to keep the application responsive.
    Another way to avoid multi-threading is starting a new QProcess for every job that has to be done and connect some signals to your application to keep track of progress.

Similar Threads

  1. Replies: 4
    Last Post: 1st May 2010, 14:02
  2. SQLite3 and Qt
    By k12yp70n in forum Newbie
    Replies: 3
    Last Post: 18th March 2009, 15:18
  3. Model / Threading Advice
    By tntcoda in forum Qt Programming
    Replies: 6
    Last Post: 19th November 2008, 14:02
  4. Sqlite3 window problem
    By giusepped in forum Qt Programming
    Replies: 11
    Last Post: 7th November 2008, 02:18
  5. problem: inserting a BLOB into sqlite3 with QT4.3
    By oscar in forum Qt Programming
    Replies: 1
    Last Post: 18th November 2007, 12:38

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.