Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. 'setenv' was not declared in this scope

'setenv' was not declared in this scope

Scheduled Pinned Locked Moved C++ Gurus
6 Posts 2 Posters 4.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
    MichaelStein
    wrote on last edited by
    #1

    I have a function for converting the time to the local time in my timezone. However, whenever I run the program, I get the error "'setenv' was not declared in this scope"(line 22). I thought that I had #included all the right libraries (<cstdlib.h> <stdlib.h> etc.) and it still gives me this error. Note that the function putenv does not give the same error and according to "this":http://www.codecogs.com/library/computing/c/stdlib.h/getenv.php?alias=setenv page they are meant to be in the same library. Anybody know what the problem is?

    @QTime convert_to_tz(QDate theday, double thetime, QString timezone){
    struct tm tm;
    time_t timenum;

    //mktime has the side effect of normalizing tm
    tm.tm_min=tm.tm_hour=0;
    tm.tm_sec=static_cast<int>(thetime6060);
    tm.tm_mon=theday.month()-1;
    tm.tm_mday=theday.day();
    tm.tm_year=theday.year()-1900;
    tm.tm_isdst=0;
    //tm.tm_gmtoff=0;

    //Get timenum for the UTC time.
    putenv("TZ=UTC");
    tzset();
    timenum=mktime(&tm);

    //Convert back to the requested local timezone
    const char * timezoneChar = timezone.toAscii().data();
    setenv("TZ",timezoneChar,1);
    tzset();
    localtime_r(&timenum,&tm);

    //return a value
    return QTime (tm.tm_hour,tm.tm_min);
    }@

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

      Info about Platform/Compiler version?

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

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

        It says 4.6.3 under Qt version in the Build settings tab. I think that's the compiler version?
        Thanks in advance

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mcosta
          wrote on last edited by
          #4

          Operating system??

          Once your problem is solved don't forget to:

          • Mark the thread as SOLVED using the Topic Tool menu
          • Vote up the answer(s) that helped you to solve the issue

          You can embed images using (http://imgur.com/) or (http://postimage.org/)

          1 Reply Last reply
          0
          • M Offline
            M Offline
            MichaelStein
            wrote on last edited by
            #5

            Win 7

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mcosta
              wrote on last edited by
              #6

              If you're using Visual Studio version of Qt the setenv function could be not available.
              You could use putenv instead.

              Anyway I suggest to find a solution based on Qt API; like

              @
              QDateTime dt (theday, QTime(0, 0, 0), Qt::UTC);
              QTime tt = dt.addSecs(thetime).toLocalTime().time();
              return QTime(tt.hour(), tt.minute())
              @

              Once your problem is solved don't forget to:

              • Mark the thread as SOLVED using the Topic Tool menu
              • Vote up the answer(s) that helped you to solve the issue

              You can embed images using (http://imgur.com/) or (http://postimage.org/)

              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