Results 1 to 2 of 2

Thread: Working with QThread

  1. #1
    Join Date
    Jul 2007
    Location
    BY.Minsk
    Posts
    90
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Working with QThread

    Prompt how to implement the following features:

    My application is a lot Thread server and receives the job to copy files from one directory to another. After receives a job is entered into the database and get in the queue.With the help of a timer, I queried the database every 10 seconds, and derive from the base of your new job. Each new task of copying a file is executed in a separate thread.Now you need to be able to suspend the execution in advance of copying the file / interrupt the flow.
    Prompt how to make sure that I at any time to stop the flow.

    application of this:


    Qt Code:
    1. void Server::TimerShot()
    2. {
    3. CWorkThread *WThread = new CWorkThread(this);
    4. connect(WThread, SIGNAL(finished()), WThread, SLOT(deleteLater()));
    5. WThread->start(QThread::HighPriority);
    6. }
    To copy to clipboard, switch view to plain text mode 



    Qt Code:
    1. void CWorkThread::run()
    2. {
    3. CWorkFiles files;
    4.  
    5. sInfo = db.GetNewTask();
    6. db.CloseDB();
    7.  
    8. //File Operation blocked. While the file is not copied more than walk.
    9. if(files.CopyFileExPrg(QDir::toNativeSeparators(sInfo.cFileName),
    10. QDir::toNativeSeparators(sGInfo.cDstPath), true, false, sInfo.nSysId))
    11. {
    12. //OK
    13. db.ChangeState(3, sInfo.cObjName, sInfo.cFileName, sInfo.nSysId);
    14. db.CloseDB();
    15. break;
    16. }
    17. else
    18. {
    19. //ERROR
    20. db.ChangeState(33, sInfo.cObjName, sInfo.cFileName, sInfo.nSysId);
    21. db.CloseDB();
    22. break;
    23. }
    24. }
    To copy to clipboard, switch view to plain text mode 

  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: Working with QThread

    I suggest you read about QThreadPool and QRunnable and QFuture.
    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. need help in QThread()
    By wagmare in forum Qt Programming
    Replies: 3
    Last Post: 18th December 2008, 13:21
  2. GUI thread and Working thread comunication
    By FasTTo in forum Qt Programming
    Replies: 2
    Last Post: 13th September 2007, 15:31
  3. QThread exec proplem to stop...
    By patrik08 in forum Qt Programming
    Replies: 29
    Last Post: 21st May 2007, 07:51
  4. Qthread Issue?
    By vishal.chauhan in forum Newbie
    Replies: 3
    Last Post: 29th March 2007, 08:50
  5. Is it possible to create a QThread without inheriting ?
    By probine in forum Qt Programming
    Replies: 6
    Last Post: 23rd March 2006, 22:51

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.