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. 'qEnvironmentVariable' was not declared in this scope
Forum Updated to NodeBB v4.3 + New Features

'qEnvironmentVariable' was not declared in this scope

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 1.1k Views 2 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.
  • Seb TurS Offline
    Seb TurS Offline
    Seb Tur
    wrote on last edited by
    #1

    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

    jsulmJ 1 Reply Last reply
    0
    • Seb TurS Seb Tur

      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

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

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

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

      1 Reply Last reply
      0
      • Seb TurS Offline
        Seb TurS Offline
        Seb Tur
        wrote on last edited by Seb Tur
        #3

        @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
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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
          2
          • Seb TurS Offline
            Seb TurS Offline
            Seb Tur
            wrote on last edited by
            #5

            Solution : use qgetenv()

            U 1 Reply Last reply
            1
            • Seb TurS Seb Tur

              Solution : use qgetenv()

              U Offline
              U Offline
              ussef
              wrote on last edited by
              #6

              @Seb-Tur This fixed my error, thanks!

              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