0

I have a MFC project which do something like this

CString getTimeString( void ) { SYSTEMTIME systemTime; CString datestr;

GetSystemTime( &systemTime );

datestr.Format( "%02i/%02i/%04i, %02i:%02i:%02i",
    systemTime.wDay, systemTime.wMonth, systemTime.wYear,
    systemTime.wHour, systemTime.wMinute, systemTime.wSecond );

return ( datestr + "; " + get_file_info().PName.c_str() + ", " + get_version_info().PVersion.c_str() );

}

Now I replicating something like this in QT

char* getTimeString( void )
{
     QDateTime      systemTime = QDateTime::currentDateTime();
      QString       datestr  = systemTime.toString() ;



    /*GetSystemTime( &systemTime );

    datestr.Format( "%02i/%02i/%04i, %02i:%02i:%02i",
        systemTime.wDay, systemTime.wMonth, systemTime.wYear,
        systemTime.wHour, systemTime.wMinute, systemTime.wSecond );

*/

    return ( datestr.toStdString().c_str() + "; " + get_file_info().PName.c_str() + ", " + get_version_info().PVersion.c_str() );
}

It throws an error
" Expression must have integral or enum type... "
ON closer Look I realise that since its not std::String we cannot add up like this .. S o My question is how would I acheive return function in QT in exact same way as its done in VS2010( shown above).

samprat
  • 2,150
  • 8
  • 39
  • 73

1 Answers1

1

I would do that in the following way:

[..]
return QString("%1; %2, %3")
               .arg(datestr)
               .arg(QString(get_file_info().PName.c_str()))
               .arg(QString(get_version_info().PVersion.c_str())).toLocal8Bit().data();
vahancho
  • 20,808
  • 3
  • 47
  • 55
  • Hi eveyrone , I have made the changes as suggested by Vaqhancho but I g get error like :\mydir\application\libs\lib_know/FileVersioninfo.h(83): error C2440: 'default argument' : cannot convert from 'int' to 'know::FileVersionInfo::Pcalculator' 1> Source or target has incomplete type 1>C:\mydir\application\libs\lib_know/FileVersioninfo.h(83): error C2548: 'know::init_file_version_info' : missing default parameter for parameter 1 1>MessagingInterface.cpp(32): error C2143: syntax error : missing ';' before '.' – samprat Dec 04 '13 at 11:59
  • Actually in other project the above function with CString works fine . I am wondering is it something to relate with QVariant? – samprat Dec 04 '13 at 12:00
  • I hav tried that as well before posting teh reply but it doesnt work. I have tried even something like this one QString convert(const std::string& s) { return QString::fromStdString(s); } – samprat Dec 04 '13 at 15:24
  • char* getTimestampString( void ) { QDateTime systemTime = QDateTime::currentDateTime(); QString datestr = systemTime.toString() ; return( QString("%1; %2, %3").arg( datestr ) .arg( convert( get_file_version_info().ProductName ) ) .arg( convert( get_file_version_info().ProductVersion ) ) ) ; // return (" implement later"); } – samprat Dec 04 '13 at 15:24
  • I have reposted my qs in different post ( as I thought its different problem ) and someone has suggested that "there is no overload of arg that takes a char* but i didnt get what he meant by that line. – samprat Dec 04 '13 at 15:26
  • below are link of my new post http://stackoverflow.com/questions/20375642/cannot-convert-from-int-missing-default-parameter-for-parameter-1 – samprat Dec 04 '13 at 15:27
  • @samprat, the error you got refers to `know::init_file_version_info` and not to the Qt stuff. What is that? Investigate why the compiler complains. On which function call? – vahancho Dec 04 '13 at 15:28
  • Thanks mate for all the help you have given to me.. The issue is taht know::init_file_version_info is being used by lot of other projects running on vs2010 and in linux and all these projects used the function which I have posted under vs2010 and they dnt throw any error , just to be on safe side I have compiled old projects and they seem to be working fine .. so I feel something is wrong on my prject. I have commented by whole function and it stil throws error if I include those header files .. so may be something is wrong with inclusion of those header files – samprat Dec 04 '13 at 16:04
  • SOLVED !!!!!.. the know::init_file_version_info was using some boost library which I have not included by using hit and trail method It works now... – samprat Dec 04 '13 at 16:27