'setenv' was not declared in this scope
-
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);
}@ -
It says 4.6.3 under Qt version in the Build settings tab. I think that's the compiler version?
Thanks in advance -
Win 7
-
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())
@