Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    Convert enum in QProcess to string

    General and Desktop
    3
    4
    2456
    Loading More Posts
    • 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
      medvedm last edited by

      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 Reply Quote 0
      • M
        MuldeR last edited by

        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 Reply Quote 0
        • M
          medvedm last edited by

          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 Reply Quote 0
          • X
            Xander84 last edited by

            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 Reply Quote 0
            • First post
              Last post