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. QT c++ code for mounting and unmounting USB flash drive?
Forum Updated to NodeBB v4.3 + New Features

QT c++ code for mounting and unmounting USB flash drive?

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 8.5k Views 2 Watching
  • 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.
  • L Offline
    L Offline
    Lineaxe
    wrote on last edited by
    #1

    On the hunt for some examples on the net.. Anyone here run into this situation ?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You can use QProcess to call mount/umount with the adequate options.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • L Offline
        L Offline
        Lineaxe
        wrote on last edited by
        #3

        wow that was fast.. I am getting back into c++ , QT seems to be a fairly robust IDE. It packs more than you first expect...
        thanks for your answer...Heh ,actually I was planning on calling mount and umount as a process call . I thought maybe QT might have a class for this somewhere...

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          No it doesn't, that's a bit too platform specific.

          Don't forget a thing: mount and umount requires admin privileges to work, unless the mount points are setup to be mountable by the user.

          By the way it's Qt, QT stands for Apple QuickTime

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mcosta
            wrote on last edited by
            #5

            Hi,

            just to be precise, Qt is not an IDE.

            Anyway, instead of using an external process I suggest to use the C API mount(); here you can find the manual

            Once your problem is solved don't forget to:

            • Mark the thread as SOLVED using the Topic Tool menu
            • Vote up the answer(s) that helped you to solve the issue

            You can embed images using (http://imgur.com/) or (http://postimage.org/)

            1 Reply Last reply
            0
            • L Offline
              L Offline
              Lineaxe
              wrote on last edited by
              #6

              Wow , you guys know this environment very well ... I am coming over from using VS, Eclipse, and a couple of other developement environments. I was so spoiled when I was C# programming in .NET :)

              1 Reply Last reply
              0
              • J Offline
                J Offline
                Jimit Rupani
                wrote on last edited by
                #7

                Hi, Use this i have used QProcess as SGaist suggested.

                QProcess* chkproc = new QProcess();
                chkproc->start("blkid");
                chkproc->waitForFinished();
                
                QString output(chkproc->readAllStandardOutput());
                
                int start = output.indexOf("/dev/sd", 0, Qt::CaseInsensitive);
                
                QString usbPath = output.mid(start, 9);
                QProcess* process = new QProcess();
                process->start("mount "+ usbPath +" /media/usb");
                process->waitForFinished();
                
                QProcess::ExitStatus Status = process->exitStatus();
                if (Status == 0)
                {
                    qDebug() << "Usb Inserted!";
                }
                
                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Jimit-Rupani you are leaking at least two object each time you call that routine. Use the stack for the QProcess objects.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  2

                  • Login

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