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

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

  • Lifetime Qt Champion


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

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

  • Lifetime Qt Champion

    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

  • 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

  • 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 :)

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

    QProcess* chkproc = new QProcess();
    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");
    QProcess::ExitStatus Status = process->exitStatus();
    if (Status == 0)
        qDebug() << "Usb Inserted!";

  • Lifetime Qt Champion

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

Log in to reply