Qt Forum

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

    Solved 'qEnvironmentVariable' was not declared in this scope

    General and Desktop
    4
    6
    357
    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.
    • S
      Seb Tur last edited by

      QString sysuser = qEnvironmentVariable("USER");
      works on Opensuse
      but i cannot build the same code on neither Ubuntu nor Win

      I tried including QtGlobal but did not help

      jsulm 1 Reply Last reply Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion @Seb Tur last edited by

        @Seb-Tur Which Qt version?
        Please show the code.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • S
          Seb Tur last edited by Seb Tur

          @Seb-Tur said in 'qEnvironmentVariable' was not declared in this scope:

          QString sysuser = qEnvironmentVariable("USER");

          on Opensuse where it works qt 5.15

          on Ubuntu fails on qt 5.9.5
          on win fails on qt 5.5

          code is very simple

          void MainWindow::on_pushButton_clicked()
          {
              QString sysuser = qEnvironmentVariable("USER");
              if (sysuser.isEmpty()) sysuser = qEnvironmentVariable("USERNAME");
          
              ui->pole->setText(sysuser);
          }
          
          
          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            Hi,

            As stated in the documentation of qEnvironmentVariable it was added in Qt 5.10.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 2
            • S
              Seb Tur last edited by

              Solution : use qgetenv()

              U 1 Reply Last reply Reply Quote 1
              • U
                ussef @Seb Tur last edited by

                @Seb-Tur This fixed my error, thanks!

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post