Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-20788

QProcessEnvironment::systemEnvironment() not retrieves all env. variables when application running through "Start and Debug External Application..."

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Incomplete
    • Icon: Not Evaluated Not Evaluated
    • None
    • 4.7.3
    • Core: I/O
    • None
    • Windows 7, MinGW

      Simple example:

      #include <QtCore/QDebug>
      #include <QtCore/QProcessEnvironment>
      #include <QtGui/QApplication>
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          foreach (QString s, QProcessEnvironment::systemEnvironment().toStringList())
              qDebug() << s;
          return 0;
      }
      

      1. When run application by starting .exe file - it's ok and systemEnvironment() contains all variables.
      2. But when I trying to run application by "Debug - Start Debugging - Start and Debug External Application..." - systemEnvironment() not contains many variables that it must contains. E.g. I need variable "APPDATA" that not in list. qgetenv() also not contains all env. variables in this case.

      It's very inconvenient bug when your application write config file in "$APPDATA" and you have to debug your application after "make install" command (with "Start and Debug External Application...").

      I found workaround for this (when you need to debug app with having all env. variables).
      1. Add stopping message box at begin of main():

      #include <QtCore/QDebug>
      #include <QtCore/QProcessEnvironment>
      #include <QtGui/QApplication>
      #include <QtGui/QMessageBox>
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          QMessageBox::information(0, "", "pause");
          foreach (QString s, QProcessEnvironment::systemEnvironment().toStringList())
              qDebug() << s;
          return 0;
      }
      

      2. Put breakpoints
      3. Run app (without debug, Ctrl+R)
      4. Attach to process (Debug - Start Debugging - Attach to Running External Application...)
      5. Wait for attaching, click F5 for step over assembler code
      6. Click "OK" on message box
      7. Debug starts and all the env. variables will be available by QProcessEnvironment::systemEnvironment()

      P.S. I test this bug only in Windows and don't know about it in Linux and MacOS.

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            Unassigned Unassigned
            joe Sam Protsenko
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes