Results 1 to 7 of 7

Thread: Multi-threading

  1. #1
    Join Date
    Apr 2012
    Location
    Porto
    Posts
    38
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Multi-threading

    Hello guys,

    I come here to know about your opinion. I want have 2 threads running in my programm.

    Threads:
    1. GUI
    2. Logical code


    Main.h
    start running the 2 threads

    Mainwindow
    using the 2 threads

    Others dialogs (UI)
    using the 2 threads

    Is it possible right?

    What best method to using this? QT Concurrent, QThreads ... ?

    Thanks
    Best Regards,Pedro Lopes

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Multi-threading

    It really depends what you need those threads for.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Apr 2012
    Location
    Porto
    Posts
    38
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Multi-threading

    Thanks for your quick reply.

    I would like something as...

    1 programm and 2 threads. One thread to GUI and other for worker. The GUI speaks with the worker for her to do something.

    For example...

    in my mainwindow i have 1 button ("Count to 10000").this button calls the logical thread (logical class) and count to 10000. And simultaneously is showing wait dialog.

  4. #4
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Multi-threading

    yes, this is possible. You should consider QThread and qt concurrent according to your needs.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Multi-threading

    Quote Originally Posted by plopes21 View Post
    1 programm and 2 threads. One thread to GUI and other for worker. The GUI speaks with the worker for her to do something.
    This still doesn't determine what the worker thread is used for.

    in my mainwindow i have 1 button ("Count to 10000").this button calls the logical thread (logical class) and count to 10000. And simultaneously is showing wait dialog.
    Well... for that you don't need a worker thread.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Apr 2012
    Location
    Porto
    Posts
    38
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Multi-threading

    In my mainwindow i have
    Qt Code:
    1. th = new QThread;
    2. qDebug()<< "ID->" << thread()->currentThreadId();
    3. worker= new Worker(&ClassHasSomethingToDo);
    4. worker->moveToThread(th);
    5. th->start();
    To copy to clipboard, switch view to plain text mode 

    So, as I have above I can get two threads running in simultaneous.

    Mainwindow has a button when is clicked, shows a dialog.

    This dialog has to communicate with the class(ClassHasSomethingToDo) passed the Worker.

    In dialog I have

    Qt Code:
    1. QInitTokenDialog(ClassHasSomethingToDo*todo, QWidget *parent)
    2. this->todo=todo;
    3. connect(todo, SIGNAL(message(QString)), ui->textEdit, SLOT(setText(QString)));
    4. QMetaObject::invokeMethod(todo, "getMessage", Qt::AutoConnection);
    To copy to clipboard, switch view to plain text mode 

    I cant catch the signal emitted by ClassHasSomethingToDo. Why guys?

    Thanks for all answers, and sorry my English :P

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Multi-threading

    How are we supposed to know that? Does your connect() statement return true or false? Do you get any warnings on the console while the program is running?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Qt Multi Threading RePainting Problem
    By Mohammad in forum Qt Programming
    Replies: 4
    Last Post: 12th January 2012, 15:52
  2. Slow Multi-Threading
    By AwDogsgo2Heaven in forum Qt Programming
    Replies: 5
    Last Post: 19th July 2009, 21:36
  3. Multi-threading
    By lixo1 in forum Qt Programming
    Replies: 5
    Last Post: 22nd June 2009, 13:22
  4. Multi threading ...
    By kiranraj in forum Qt Programming
    Replies: 2
    Last Post: 18th June 2007, 16:51
  5. Multi-threading
    By shamik in forum Qt Programming
    Replies: 15
    Last Post: 28th November 2006, 10:22

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.