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();
题
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).
解决方案
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();