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. Convert enum in QProcess to string

Convert enum in QProcess to string

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.8k 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.
  • M Offline
    M Offline
    medvedm
    wrote on last edited by
    #1

    I'm writing some code which responds to the error() signal in QProcess. What I'd like to do is easily output the value of the QProcess::ProcessError that gets passed in... I was going to take a generic approach when I dug through the code and found that they don't use Q_ENUMS inside of QProcess which would have made the enum values easily QString-able. See:

    https://qt.gitorious.org/qt/qtbase/source/d52b00e1d3cc60c81b54a89d6da488dc4bbce384:src/corelib/io/qprocess.h

    As opposed to enums in the Qt namespace, which are Q_ENUMed:

    https://qt.gitorious.org/qt/qtbase/source/d52b00e1d3cc60c81b54a89d6da488dc4bbce384:src/corelib/global/qnamespace.h

    Is there any "rule" for Qt developers like, if you have a class that uses enumerated values publicly, you should tell moc about them with Q_ENUMS so that people can write really friendly error handlers.

    Should I submit this as a bug/feature request? Is there some means of getting at this thing that I don't know about? It is my understanding that one must use Q_ENUMS if you are going to try and use QMetaEnum.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MuldeR
      wrote on last edited by
      #2

      You could do something like:
      @#define ENUM_TO_STR(X,Y) do
      {
      if((X) == (Y) return QString::fromLatin1( #Y );
      }
      while(0)

      QString error2str(const int &error)
      {
      ENUM_TO_STR(error, QProcess::FailedToStart);
      ENUM_TO_STR(error, QProcess::Crashed);
      ENUM_TO_STR(error, QProcess::Timedot);
      ENUM_TO_STR(error, QProcess::ReadError);
      ENUM_TO_STR(error, QProcess::WriteError);
      ENUM_TO_STR(error, QProcess::UnknownError);
      }@

      My OpenSource software at: http://muldersoft.com/

      Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

      Go visit the coop: http://youtu.be/Jay...

      1 Reply Last reply
      0
      • M Offline
        M Offline
        medvedm
        wrote on last edited by
        #3

        Yeah, I was trying to avoid writing any kind of specific case function - given Qt has a generic way of getting information about enums, it would be awesome if people registered their enums.

        1 Reply Last reply
        0
        • X Offline
          X Offline
          Xander84
          wrote on last edited by
          #4

          what about QIODevice::errorString() ?
          QIODevice is the base class of QProcess and there is an example that uses errorString() with a QProcess object, so you might just give it a try. :)

          see here: http://qt-project.org/doc/qt-5/qprocess.html#setProcessChannelMode
          @
          QProcess builder;
          builder.setProcessChannelMode(QProcess::MergedChannels);
          builder.start("make", QStringList() << "-j2");

          if (!builder.waitForFinished())
          qDebug() << "Make failed:" << builder.errorString();
          else
          qDebug() << "Make output:" << builder.readAll();
          @

          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