Converting QString to QByteArray using toLatin1() gives a linker error
<p>I have a simple Qt-5 console application that I am developing in Visual Studio 2015. I can use Qt objects such as QStrings so I'm sure Qt is installed correctly, but I need to convert a QString to a char* so I can pass it to a library function.</p>

<p>I followed this answer: <a href="https://stackoverflow.com/questions/2523765/qstring-to-char-conversion">QString to char* conversion</a></p>

<p>So I now have code that looks like:</p>

<pre><code>QString myStr = "SomeString";
QByteArray ba = myStr.toLatin1();
const char *c_str = ba.data();
</code></pre>

<p>But when I build the solution I get the following error:</p>

<pre><code>Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: class QByteArray __thiscall QString::toLatin1(void)const &amp; " (__imp_?toLatin1@QString@@QGBE?AVQByteArray@@XZ) referenced in function _main    
</code></pre>

<p>The problem seems to be the toLatin1() call, but I have no idea why the linker can't find it, especially since I can use other QString methods with no problem.</p>