简体   繁体   中英

Expression must have integral or enum type Char*

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM