PDA

View Full Version : LNK1120: 1 unresolved externals for toUtf8 and assertion for QString::toStdString()



oop
18th February 2016, 16:13
Hi all,
I am testing with a new QT5.5 project x86 under VS2015.
Here is my little program:




#include <QtCore/QCoreApplication>
#include <QDebug>
#include <QByteArray>


1 int main(int argc, char *argv[]){
2 QCoreApplication a(argc, argv);
3 QString message="1234567890";
4
5 std::string str=message.toStdString().c_str();
6 QByteArray a1=message.toUtf8();
7
8 qDebug()<<str.c_str();
9
10 return a.exec();
11 }



The troubles:
1) After building I get error LNK2019: unresolved external symbol for QString::toUtf8() in 6);
2) If I delete the line 6) and run the program I get:
1) An assertion into minkernel\crts\ucrt\src\appcrt\heap\debug_heap.cpp in Debug mode;
2) no 'apparent' problem in release mode.



No problems under the QT Creator.

What I can search for?


Cheers,
Giorgio

Added after 21 minutes:

I seen that setting 'Visual Studio 2013 (v120)' in project property page --> Configuration Properties --> Platform toolset
the assertion does not happen and also the LNK2019 is solved.

Can some one explain me in details the motive, please?

Cheers.
Giorgio


Cheers,
Giorgio

d_stranz
18th February 2016, 17:14
Some earlier versions of Qt were built with the MSVC flag "treat wchar_t as a built-in type" set to FALSE. Current versions now have it set to TRUE. Look at the Properties->Configuration Properties->C/C++->Language page in MSVC. This would cause errors with conversion between QString and std:wstring / std::string.

In addition, MSVC 2015 is not yet officially supported by Qt, whereas MSVC 2013 is. Using VS 2013 as the platform toolset changes some of the defaults and that allows a Qt app to compile and link without complaints.

I assume that the upcoming Qt 5.6 release will have support for MSVC 2015. If not, continue to use the 2013 toolset setting.

oop
18th February 2016, 17:32
Thank you very much, I will keep in mind your kindly given info.

Giorgio