Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. No disk message in Windows
Forum Updated to NodeBB v4.3 + New Features

No disk message in Windows

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 1.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    samdol
    wrote on last edited by
    #1

    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

    jsulmJ 1 Reply Last reply
    0
    • S samdol

      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

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply
      3
      • jsulmJ jsulm

        @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?

        S Offline
        S Offline
        samdol
        wrote on last edited by
        #3

        @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.

        jsulmJ 1 Reply Last reply
        0
        • S samdol

          @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.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by jsulm
          #4

          @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()).

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          S 1 Reply Last reply
          4
          • jsulmJ jsulm

            @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()).

            S Offline
            S Offline
            samdol
            wrote on last edited by samdol
            #5

            @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

            1. Turn on computer.
            2. plugin usb drive
            3. plugout usb drive.
            4. 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.

            jsulmJ 1 Reply Last reply
            0
            • S samdol

              @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

              1. Turn on computer.
              2. plugin usb drive
              3. plugout usb drive.
              4. 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.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @samdol Are you sure you deployed your app correctly (correct DLLs)?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved