Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qt includes not working without path in include statement



  • My desktop Qt installation works fine, regardless if I point it to 5.5.1 or 5.10.0. I installed VS 2017 and Qt on my laptop so that I can work on my project in spare moments while visiting family over the holidays. I only have 5.5.1 on the destination machine (since that was the version I was using) and I have installed the extension for VS 2017. I can successfully set the target version. However, none of the include statements work on the laptop unless I add the subdirectory as part of the statement.

    For example, I must change
    #include <qstring.h> // to...
    #include <QtCore/qstring.h>

    Ultimately, I don't really care which format I use.... I just want it to be consistent so that what works on one computer will work on the other computer. Since things are currently without the subdirectory prefix, I would prefer that to work... but I can change if it is better. Is their a Qt setting or Visual Studio setting that will allow this to work on the new (or original) computer so that it is consistent?


  • Lifetime Qt Champion

    Hi,

    The official way to do includes is:

    #include <QString>
    


  • Ok... but for whatever, reason, that is not working on the laptop. It says that the file is not found.


  • Lifetime Qt Champion

    Did you try fo find that file in your Qt installation ?



  • Yes. They are all there. Every Qt file that I am trying to include is not found (there are many). It is not recursively traversing the qt folder to find included files. Yet there are no issues with the any of the files on my desktop. My guess is that either there is a VS 2017 setting that is different or there is something about the Qt extension/install on this computer that is different (in addition to its location).


  • Lifetime Qt Champion

    How are you setting the project ?
    Are you starting from a .pro file ?



  • No. The project has been done entirely in VS 2017. It was started as a new project on the desktop mentioned. I am not sure what you mean by "setting". I selected New=>Project from the File Menu in VS 2017 and then selected the traditional QT DLL project (or EXE in the single EXE case) type and went through the wizard from there. Then I re-selected the Qt version (as I usually have to do).

    To move to the laptop, I exported most of my VS 2017 settings and imported them on the laptop. I then moved the project as well. On the laptop, I used the default install directory for Qt. For the desktop I did not. However, that shouldn't matter as the QTDIR is an environment macro/variable (used in the "Additional Include Directories" tab only). I have read that sometimes the regular (not additional) VC++ include directories need to be set to fix this issue. However, the QTDIR macro is not available in this context. In addition, the QT plugin doesn't seem to mess with these settings. Since you say that a simple #include <qstring.h> is normal, I am assuming that it should not be necessary to change things...



  • I think I figured out the problem, I am not sure why it occurred though. In the Qt project settings, none of the modules I checked when I created the project (and still exist on the other machine) are checked. Apparently the VS plugin adds the appropriate directory to additional includes when the modules are checked. For whatever reason, these settings did not transfer to the laptop.



  • @primem0ver glad you solved your issue, please don't to forget to mark your post as such. Thanks!


Log in to reply