Unsolved No disk message in Windows
-
Hi,
I noticed that detecting USB drive is introduced in Qt 5.9. Since I used Qt 5.6 for my program I choose to create a snippet to detect USB drive using QDir::drives().size().
Basically, every 5 seconds it compares the number of drives to detect USB insertion or removal. I thought it would be more efficient to put this job in another thread by moveToThread().
It works fine, it could detect insertion or removal of USB drive. But after removing USB, when I restart my program, it show the following message There is no disk in the drive please insert a disk into drive \Device\Harddisk1\DR1.After googling, I think that the program still tries to find the USB drive that I have removed already. Even I completely remove registry related to the program, when I restart the program, it show the message. Only when I restart the computer, it does not show the message anymore. Does that mean after terminating program, the thread still alive? I created the thread by
myThread = new QThread(this);
in mainwindow.cpp -
@samdol The thread cannot be alive if the process is terminated - is it possible that your app isn't closed properly and is still running (without visible window). Why do you use a thread for this task? It's really not needed for such a task - just use a QTimer.
What do you do with the detected USB drive in your app? -
@jsulm
Thank you for replay. After detecting usb it goes to the QTreeView as an directory entry.
My main.cpp looks like this#include <QApplication> #include <QStyle> #include <QTimer> #include "MainWindow.h" Q_IMPORT_PLUGIN(MyPlugin) int main(int argc, char *argv[]) { QApplication app(argc, argv); MainWindow mainwindow; mainwindow.show(); mainwindow.init(); return app.exec(); }
I have implemented the following quit function in mainwindow class.
void mainwindow::quit() { if(isFullScreen()){ onToggleFullScreen(); qApp->closeAllWindows(); }else{ qApp->closeAllWindows(); } }
After running this function the mainwindow disappear. I think the program terminated completely. But the thread is still running. The parent of thread is mainwindow. Thus I think if the mainwindow is distroyed by quit(), then thread also must be destroyed but it is still running.
-
@samdol "I think the program terminated completely. But the thread is still running." - the program did not terminate at all, only window was closed. You need to terminate the thread using, for example, http://doc.qt.io/qt-5.9/qthread.html#exit (call it in quit()).
-
@jsulm
I just put qApp->quit() in closeEvent(), so whenever I close by clicking x, threads also destroyed. But the message
"There is no disk in the drive..." still pops up when I start program.
I did- Turn on computer.
- plugin usb drive
- plugout usb drive.
- start my program.
Then the message pops up. If I skip 2 and 3, the messages does not pop up.
And I finally found that QDirModel causes this problem.
When I comment out QTreeView::setModel(QDirModel),
the message does not pop up. But I dont know how I can solve this problem. I used QFileSystemModel before, but it has more serious problem such as deleting folder did not work properly... so I changed back to QDirModel.Interesting thing is that it if I run the program in Qt-Creator, it does not show the message. After running windeployqt, if I run the program, it shows the message.
-
@samdol Are you sure you deployed your app correctly (correct DLLs)?