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. [SOLVED] Usage of QRegExp

[SOLVED] Usage of QRegExp

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.3k Views 1 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.
  • S Offline
    S Offline
    srivatsa
    wrote on last edited by
    #1

    I am parsing the output of @vol@ command such that I only get the volume serial number i.e like qwer-12w2. But I get nothing, here's my code:

    @#include <QtCore/QCoreApplication>
    #include <QProcess>
    #include <QDebug>

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);
    QProcess process;
    process.start("cmd /c vol C:");

    process.waitForFinished(-1);
    QByteArray out = process.readAllStandardOutput();
    qDebug() << out;
    QRegExp rx("The Volume Serial Number is (.+)\\.");
    if(rx.exactMatch(out)){
        QString id = rx.cap(1);
        qDebug() << id;
    }
    return a.exec(&#41;;
    

    }@

    1 Reply Last reply
    0
    • TheBadgerT Offline
      TheBadgerT Offline
      TheBadger
      wrote on last edited by
      #2

      Hi,

      Took me a few seconds to figure it out but here it is:
      On my computer the output of your process ("cmd /c vol C:") is (Windows 7):
      @
      Volume in drive C is SYSTEM
      Volume Serial Number is 9C75-16CB
      @

      If you look at your RexExp pattern you would notice that your patter starts with "The" while the output does not have a "The" in (first problem).

      My output does not contain a '.' at the end: Second Problem

      My suggestion is to use a patter like:
      @
      QRegExp rx(".*Volume Serial Number is (.+)$");
      @

      That should work for what you are trying to do


      Check out my SpellChecker Plugin for Qt Creator @ https://github.com/CJCombrink/SpellChecker-Plugin

      1 Reply Last reply
      0
      • S Offline
        S Offline
        srivatsa
        wrote on last edited by
        #3

        Got it :) Thank you @Badger.

        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