Results 1 to 2 of 2

Thread: QFile locks debug environment in QThread

  1. #1
    Join Date
    Feb 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QFile locks debug environment in QThread

    Hello,
    I am using Qt4 libraries in V3.5.4 KDevelop and I am having a general debugging issue.

    I have a QFile instance in a subclassed QThread, and have noticed that whenever I try to debug step over a QFile method, the debugger completely freezes. I have tried stepping over said function calls and even stepping into said function calls, and the debugger freezes.

    Below is how I am using my code.

    Qt Code:
    1. class MyQThread : public QThread
    2. {
    3. ...
    4.  
    5. private:
    6. QFile * file;
    7. };
    8.  
    9.  
    10. MyQThread::MyQThread(QObject * parent) : QThread(parent)
    11. {
    12. file = NULL;
    13. }
    14.  
    15. void MyQThread::run()
    16. {
    17. bool doneReading;
    18. while (running) {
    19. /* get file if null */
    20. if (!file) {
    21. QString path = getPathToFile();
    22. file = new QFile(path);
    23. if (!file->open(QIODevice::ReadOnly)) { /* !! FREEZES HERE !! */
    24. delete file; /* never enters here */
    25. file = NULL;
    26. return;
    27. }
    28. }
    29.  
    30. /* never gets to here */
    31. doneReading = readSomeFileData(file);
    32.  
    33. if (doneReading) {
    34. file->close();
    35. delete file;
    36. file = NULL;
    37. }
    38. }
    39. }
    To copy to clipboard, switch view to plain text mode 

    I am pretty sure there are no open file desciptors on the files I am attempting to open b/c I have tested this code after rebooting the machine and manipulating the files in no way. Also, I have verified that I am getting the correct path.

    Are there any funny quirks about using QFile in a QThread and not the main GUI thread?

    Thanks in advance.

  2. #2
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFile locks debug environment in QThread

    well, i have tried an example and i can say for sure that u can use QFile in a subclass of QThread. Here is the code i used:

    Qt Code:
    1. void MyThread::run()
    2. {
    3. bool doneReading;
    4.  
    5. file = new QFile("C:\\Documents and Settings\\am002bh\\Desktop\\practice.pro");
    6. if (!file->open(QIODevice::Append | QIODevice::Text))
    7. return;
    8.  
    9. QTextStream out(file);
    10. out << "The magic number is: " << 49 << "\n";
    11.  
    12. }
    To copy to clipboard, switch view to plain text mode 

    issue must be somewhere else

Similar Threads

  1. Eclipse question
    By MarkoSan in forum General Discussion
    Replies: 5
    Last Post: 18th November 2008, 08:38
  2. Some very weird compilation warnings
    By MarkoSan in forum Qt Programming
    Replies: 21
    Last Post: 23rd January 2008, 16:48
  3. problem with indexes
    By MarkoSan in forum Qt Programming
    Replies: 5
    Last Post: 10th December 2007, 14:55

Tags for this Thread

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.