Why can't I find <QTcpServer>? - c++

My VS2010 can only #include <Qt/qtcpserver.h> but can't #include <QTcpServer>.
Qt assistant suggested <QTcpServer> be included to apply TCP server but it seems this header cannot be found by my VS2010, but it can find <Qt/qtcpserver.h> and these two headers seems to be the same.
Are they the same and why can't I find <QTcpServer> ?
PS:
I'm currently using Qt4 plugin with VS2010.
Here's a snapshot of my VS project files:
No .pro file there.

You need to have
QT += network
in your .pro file to get the Qt networking headers and library correctly set up for your project.
For the Qt Visual Studio Add-in, look at the second tab of the project settings dialog box.

In your Qt project settings, add the network module. A guide with pictures:
http://doc.qt.digia.com/vs-add-in/vs-addin-managing-projects.html

Related

issue of including QtGui files in building a c++ based software

I am not expert in c++ and I am trying to install a software which is based on c++; during the building the files in Qt Creator, once it reaches to this line to include
#include <QtGui/QMainWindow>
#include <QtGui/QGraphicsSceneMouseEvent>
it shows error
/home/ubuntu/Ezys/source/Ezys_GUI/ezys_gui.h:12: error: QtGui/QMainWindow: No such file or directory
#include <QtGui/QMainWindow>
^
I checked the place of QtGui, which is /usr/include/qt4/QtGui and all files are there. I do not know what is the reason cannot find the files and include them.
Could someone please help me? Thanks
I think you're using the wrong kit for your project in Qt Creator, probably one based on Qt 5. See if you have a kit for Qt 4 or create a new one, then reconfigure your project to use it.

Qt Ui Existing But Ui Header and Source Not Existing

I have received a demo Qt project for a product.
I am trying to build the project and run it.
I am getting such a kind of error in Qt Designer when I try to build the project.
It says ui_FOO.h does not exist.
I see that FOO.ui (the qt designer form exists) but source and header files for it do not exist. And thats why i am getting the error.
What should I do to be able to build and run my project?
Add the following line to the pro file to get uic generate the C++ header from the ui file:
FORMS = FOO.ui
and build your project again.
You can find more information from Using a Designer UI File in Your Application.
Oh I got it.
This is a qt4 project as it is written in manual.
I went under tools->options->build&run->qtversions and added qmake-qt4
Then under the kit manually added a kit which uses the qtversion that i just specified.
Then under projects tile clicked on add kit and the kit appeared.
I removed the qt5 kit.
Now those ui_foo.h file is generated in its corresponding build path.

Qt creator direct file include

I am using Qt Creator 3.2.2 for windows. I have created an example project widget application project and that's okay. The problem is I had to add some external libraries (.c and .h files) that are in the project folder. The problem is they are not all in the same place but mixed in subcatalogs. Qt creator seemed to add them all correctly.
But the problem now is that I cannot use for example:
#include <somefile.h>
Because it says that there is no such file. Autocomplete also doesn't see it. I have to do:
#include <dir/deeper_dir/somefile.h>
And the whole library is created the way that every file is reachable from everywhere. Also I would not like to change that.
How can I make all files visible within the project?
Add the path to your headers into your .pro file with INCLUDEPATH:
INCLUDEPATH += path_to_the_folder_with_your_headers
After that you will be able to include any file in that folder just with #include <filename>
add
INCLUDEPATH += dir/deeper_dir/
in your pro file.

QMediaPlayer, QSound class - unable to #Include files (files are there)

I have been trying to play a simple audio file using:
http://qt-project.org/doc/qt-5/qmediaplayer.html and
http://qt-project.org/doc/qt-5/QSound.html
I am using Qt 5.3 but the problem is, when I type #include QMediaPlayer or QSound, QtCreator keeps underlining them with red because it can't find them. The thing is, the files are there. They are located in QtMultimedia/ and I have seen them. When I try to prefix QtMultimedia/QMediaPlayer or QtMultimedia/qmediaplayer.h it still can't find them.
If I type #include "QtMultimedia/" the auto-complete drop down in the text editor only shows QtMultimedia/QtMultimediaDepends. Normally you get a list of all the files in the folder but not with this one.
Looks like there is something wrong with the paths. How do I fix them? I am using a Windows machine.
Edit: I have included project settings - see screenshots.
I think, after you modified your .pro file, You didn't run the qmake.
build-> run qmake
qmake will generate the makefile you need to build the src code.
if you only change the .pro file, but didn't run it. Nothing is changed.
and that is reason, you create a new project and it is working.
Ok I figured it out. It's a problem with my Qt version.
My Qt 5.3 version is a custom compiled one. When I select the included version that came with the installer, QSound is found. When I change the kit to the custom compiled one, the file cannot be found. I must have forgotten to include some sort of multimedia option to the configure script during compilation.
Now the question is what is the missing option, I will need to do more reading...
Of course, comments and suggestions are welcome :)
You have to add the word 'multimedia' in your .pro file:
QT += core GUI
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets multimedia

How to create empty Qt project in visual studio 2010

Using visual studio C++ 2010 Ult.
I have compiled and instaled Qt libraries and visual studio add-in is installed into VC++ so I'm basicaly able to build Qt applications using Qt templates ofered from VS add-in.
I'm also able to include Qt headers and all works just fine...
installation has been done using VSC++ command promt, full build using
configure and nmake then.
QTDIR and PATH are properly seted up.
Qt libs are installed into:
(QTDIR) C:\Users\Admin\Documents\Libraries\Qt
(PATH) C:\Users\Admin\Documents\Libraries\Qt\bin
BIG BUT:
when crating new empty(or other non Qt template) project I can't include any Qt header so my question is how to enable this.
I want to set this so I can in all my future projects simply write:
#include <Qapplication>
#include <Qlabel> //etc...
thanks alot.
Maybe you can use the user properties for that? Set up the include and library paths there, then you should have Qt available for all projects.
See here: http://blogs.msdn.com/b/vsproject/archive/2009/07/07/vc-directories.aspx
For some reason VS can't find Qt headers. I think the only possibility is that you have not specified Qt include paths in the project (not for VS, just for a project). VS add-in always specifies these paths according to the user settings. The basic ones are ($(QTDIR)\include), $(QTDIR)\include\QtCore and $(QTDIR)\include\QtGui. The last one is necessary only when creating non-console GUI applications.