[solved]Sporadic errors with #include



  • Hello everyone, I just made the switch from Ubuntu to OpenSuse and installed QtCreator yesterday, and I'm having some trouble that I simply cannot figure out. Whenever I create a new project, even if the code is directly copied and pasted from an example which I know works, when I click run It returns a "no such file or directory" error for one or more of my includes (e.g. QtGui). However, oddly enough, if I use "explore Qt c++ examples" on the welcome screen of QtCreator to load an example, it will compile correctly upon pressing build, even if it uses the same includes which it had earlier claimed didn't exist. Even when the examples do work, however, they will sporadically revert back to saying no such file, especially if I try to build another application which fails or try to build the examples outside of QtCreator from g++, make, or another ide. Deleting and reloading the examples usually fixes this, but I still cannot get any outside code to compile.

    I've tried everything I can think of, down to copying my code over one of the examples. When I do this, everything will seem fine until suddenly the squiggly green line appears under my include statement and the build fails. I'm at my wits' end, can anyone help me with this?

    p.s. forgot to mention, In any IDE other than QtCreator I have had absolutely no luck at all with including Qt libraries, it always fails in some form or another.



  • Are you using the system-provided QT package or one that you built yourself? If using the system one do you have the qt development package installed?

    What happens when you try and build your app from the command line? To do this cd into the app directory and do "qmake && make". Can you post the output of this here please?



  • I have the system provided package from the opensuse installation dvd (md5 sum verified) with the qtdev package installed. I am away from my computer right now but every time i compiled from command line qmake executed without errors and make returned error code 1. I can post the exact output later today.



  • "This":http://postimage.org/image/217iqgslg/ is a screenshot of an example which I just opened from the main page, compiling and running perfectly in QtCreator,

    "This":http://postimage.org/image/217m1jhl0/ is the output from qmake/make,

    and "this":http://postimage.org/image/217np2u2s/ is the same exact example, unchanged, subsequently failing to run under QtCreator.

    Any program which I actually enter myself, regardless of whether I attempt to compile outside of QtCreator, has the exact same result.



  • You need to tell qmake to add the necessary include paths to the QtNetwork module. Add this to your .pro file and re-run qmake and make or build form qt-creator:

    @
    QT += network
    @

    I see that you made the .pro file using

    @qmake -project@

    That is fine to get a basic .pro file but if you use anything other than QtCore or QtGUI then you need to customise the resulting .pro file. In this case the QtNetwork headers were not being found.

    Does that work for you now?



  • That worked perfectly... I had a feeling I was overlooking something simple like that. I'm sorry, I'm very new to Qt, I've been using Java Swing for years very closed-mindedly to other options. So if I were to write my own Qt Application, how would I go about generating a pro file with the necessary information? The tutorial I had been following told me -project would do the trick, apparently that isn't correct. Needless to say I am searching for a more in-depth resource to learn Qt.

    Thank you very much for your time and responses, you've been an enormous help. I apologize for it simply being a matter of my own inexperience

    edit: never mind, I think I'm beginning to understand. qmake -project creates a basic pro file, which I then customize before I run qmake/make? Correct?



  • [quote author="eyeck" date="1301757423"]That worked perfectly... I had a feeling I was overlooking something simple like that.
    [/quote]

    No problem. That's why this forum is here. Any problem big or small will get looked at as long as the poster is polite, willing to try things and posts sensibly worded questions ;-)

    [quote author="eyeck" date="1301757423"]
    I'm sorry, I'm very new to Qt, I've been using Java Swing for years very closed-mindedly to other options. So if I were to write my own Qt Application, how would I go about generating a pro file with the necessary information? The tutorial I had been following told me -project would do the trick, apparently that isn't correct. Needless to say I am searching for a more in-depth resource to learn Qt.
    [/quote]

    Welcome to Qt ;-)

    [quote author="eyeck" date="1301757423"]
    Thank you very much for your time and responses, you've been an enormous help. I apologize for it simply being a matter of my own inexperience

    edit: never mind, I think I'm beginning to understand. qmake -project creates a basic pro file, which I then customize before I run qmake/make? Correct?[/quote]

    Yes that is correct. Qt-creator will also create you a basic .pro file when you use it to create a new project.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.