Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, everybody.

I'm currently working on a module of a project. Since the UI is created using Qt (by another fellow in my group), so I have to use classes like QString and QDir and so on. But I'd like to use VS instead of QtCreator to do the coding since I'm not drawing the UI.

I downloaded the latest Qt 5.5 open-source version for Windows from its website. Its root folder is D:\Qt\5.5\msvc2013_64. Inside I found the "lib" folder with many ".lib" files and "include" folder with relevant headers. So I imported both of them into my VS project. And I added the "Qt5Cored.lib" to my VS project's "Additional Dependencies" option of the linker.

I wrote a very simple test to see if this configuration works. (Using QString and QDir).

But the linker constantly report LNK2019 on QString::QString and QDir::setPath and many other Qt's stuff.

What am I doing wrong or I simply can't do Qt-coding in VS without an add-in?

Thanks in advance!
Posted

Because you are working on the project as group everybody should have the same development setup. So I would ask your fellow how he setup his Qt installation and help you doing the same on your machine. Then you should have no problems.

Read on if you still want a manual setup.

If he is not using a pre-build Qt version but had compiled it, you must use the header files and libraries build by him or build them on your machine using the same settings.

If he uses a pre-build Qt version you must install the same development version of that build containing the libraries, DLLs and header files. Don't use the Qt sources when not building Qt. The reason is that Qt has a lot of build options that will create build specific include files (qconfig.h) that are included by all other header files.
 
Share this answer
 
Comments
threedts167 9-Nov-15 6:47am    
He installed Qt on his machine using the online installer provided by Qt's official website and I did the same to install the same Qt version on my machine so we should have the same configuration. The Qt library is pre-compiled after the installer finished installation. The reason why my teammate doesn't have my problem is because he is using QtCreator so it's all working for him. I have tested and confirmed that the same code can compile and run without any problem using QtCreator on my machine(wondering if there's some kind of magic done by QtCreator but I failed to do the same on VisualStudio) but would fail to link using VS. You're right about using the same development setup. I posted this question just hoping to figure out why the configuration on VS doesn't work, what am I missing.
Jochen Arndt 9-Nov-15 7:11am    
Then check your project settings.

Add the pathes for the Qt include and library files to the general path settings. So you don't have to use full pathes later.

Then add the library / DLL names to the dependencies (I understand that you have done this). Note that it might be necessary to specify the debug libraries ('d' postfix) for debug builds and the release ones for release builds.

Depending on what functions you are using it may be also necessary to add other Qt libraries beside the core lib (adding more does not care when not used).

To verify that the libraries are loaded add the linker /VERBOSE option to your project settings and check if the files are found upon building.
Jochen Arndt 9-Nov-15 7:38am    
Thinking about it I see a problem.

You installed the libraries using a setup for Qt Creator which uses MinGW. But you should use a setup for Visual Studio. You may find instructions on the web passing the used QT and VS version.
threedts167 9-Nov-15 8:16am    
Yeah. By turning on the /VERBOSE switch I noticed that Qt5Cored.lib is found but not loaded (marked "unused library") like other lib files upon which the project is dependent, which is strange. The installer's name is "qt-unified-windows-x86-2.0.2-2-online.exe" and the folder that contains the lib folder is named "Qt\5.5\msvc2013_64" (I'm using VS2013 right now). I think the Qt setup on my machine is using MSVC rather than MinGW. I'll check anyway. Your advice is taking me somewhere. Thanks very much. :-)
threedts167 10-Nov-15 1:38am    
I have solved the problem by installing a qt-vs-addin, just so you know. And I can see that the addin did some macro definitions and some other stuffs in the project properties page to make Qt work on VS. I have been over-optimistic about how Qt is configured on VS. Cheers. :-)
I would go directly to the qt forums.

A google search found:
http://stackoverflow.com/questions/32757202/getting-lots-of-linker-errors-when-changed-the-qt-projects-build-directory[^]

and: https://forum.qt.io/topic/2941/failed-to-link-against-qstring-fromstdwstring-tostdwstring[^]
"VC project of Qt examples had to set "Treat wchar_t as Built-in Type" to false."
 
Share this answer
 
Comments
threedts167 9-Nov-15 1:49am    
I turned that "wchar_t as built-in" switch to false. But it didn't work. Still got LNK2019 errors. And the stackoverflow link that Hossein guy was using QtCreator but I'm using VS so I don't have .pro file or .pro.user file as he did.
[no name] 9-Nov-15 2:14am    
Re the first link - think laterally- did you clean and rebuild? http://www.qtcentre.org/content/

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900