I just started with Qt and some issues came up. I'm sure it must be a simple solution but I just can't find it.
I have two Projects, ProjectOne and ProjectTwo. I'd like you use the class foo from ProjectOne in main.cpp from ProjectTwo. When I run my Programm The Files are copied/referenced into ProjectTwo, but when i try to include foo in my main.cpp (#include "foo.h") i recieve the following error:
> main.cpp:3: error: C1083: Cannot open include file: 'foo.h':
> No such file or directory
Here's my Structure:
-ProjectOne
-ProjectOne.pro
-Headers
-foo.h
-Source
-foo.cpp
-Other files
-ProjectOne.pri
-ProjectTwo
-ProjectTwo.pro
-ProjectOne
-ProjectOne.pri
-Headers
-foo.h
-Sources
-foo.cpp
-Sources
main.cpp
Here's what i edited on my .pro and .pri files
**ProjectOne.pri**
INCLUDEPATH += $$PWD
SOURCES += $$PWD/foo.cpp
HEADERS += $$PWD/foo.h
**ProjectTwo.pro:**
include(../ProjectOne/ProjectOne.pri)
QT += core
SOURCES += foo.cpp
HEADERS += foo.h
I'm using Qt Creator 3.1.2 on Windows 7. My Programming Language is C++ and I'm compiling with VisualStudio 10 Express.
Any help is greatly appreciated!
When including a file that isn't directly in you project folder you need to include it with full or relative path.
i.e.
#include "bar/foo.h"
or
#include "../../bar/foo.h"
Related
I've currently got a QT5.5 subdirs project setup, containing so far a core library, a QT GUI app and soon in the future a tests project (probably using unittest++).
I'm following the guide for setting up the project structure: http://dragly.org/2014/03/13/new-project-structure-for-projects-in-qt-creator-with-unit-tests/
So far, the directory structure is as follows:
/Project
src/
app/
app.pro (app project, depends on core.pro)
main.cpp
mainwindow.cpp
mainwindow.h
core/
core.pro (lib project)
class.h
class.cpp
tests/ (future test project location
Project.pro (subdirs)
defaults.pri
The following is my defaults.pri file:
INCLUDEPATH += $$PWD/src
SRC_DIR = $$PWD
However, I'm not sure if I'm getting the #include directives right.
When using the #include, I have to do #include "../core/class.h". I'm not sure if this is the best way to go?? My understanding was because it's a lib, I just reference the header file as if it was within the lib, rather than location on disk?
Would namespaces solve this problem?
If you add /Project/src as include dir for your project (-I on most compilers), you can include it with:
#include <core/class.h>
I am running on a Windows 7 with Qt SDK(C++), Firmata, and Arduino Softaware
I was wondering why the firmata.h is not working
#ifndef Firmata_Boards_h
#define Firmata_Boards_h
#include <inttypes.h>
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h" // for digitalRead, digitalWrite, etc
#else
#include "WProgram.h"
#endif
the problem is when i try to compile using Qt it says
D:\SGU\Semester 8\Program\OpenCVMultithreaded\Boards.h:9: error: Arduino.h: No such file or directory
can we really use firmata on Qt? because in the internet I only found Arduino software using firmata, not on Qt itself.
I tried :
INCLUDEPATH += "D:\opencv\build\include"
INCLUDEPATH += "D:\opencv\build\include\opencv"
INCLUDEPATH += "C:\Program Files (x86)\Arduino"
INCLUDEPATH += "C:\Program Files (x86)\Arduino\hardware"
INCLUDEPATH += "C:\Program Files (x86)\Arduino\lib" I
INCLUDEPATH += "C:\Program Files (x86)\Arduino\libraries"
INCLUDEPATH += "C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino\Arduino.h"
But it doesnt work.
This is not a linking issue but a compilation issue, and has nothing to do with the specific library you are using. You probably haven't specified where to find the header files nor the library files.
In your project file (.pro) add
INCLUDEPATH += PATH_TO_ARDUINNO_HEADERS
for example PATH_TO_ARDUINNO_HEADERS can be C:/Arduino/include.
To specify libraries you need to use the LIBS variables, for example
LIBS += "-Lc:/Arduino/lib" -larduinnoshared
See the qmake reference for a complete guide on including\linking to external items
Edit:
The include path is what is going to be prefixed to find "Arduino.h".
So if the file is at
"C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino\Arduino.h"
you need to use
INCLUDEPATH += "C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino"
All the other paths you posted are invalid for this file. You put only directories containing header files in the includepath.
I downloaded pre-built win32 poppler binaries from this page. Added the path for the include folder and lib folder in the .pro file:
INCLUDEPATH += "C:\\test_folder\\poppler-0.24.5-win32\\include\\poppler-qt5"
LIBS += -L/"C:\\test_folder\\poppler-0.24.5-win32\\lib"
In main.cpp i include "poppler-qt5.h" without errors, so I would think that poppler was added correctly. However when testing it by opening a pdf file, as described here,
QString path = "C:\\Windows\\System32\\spool\\PRINTERS\\test_file.pdf";
Poppler::Document *doc = Poppler::Document::load(path);
I receive a linker error:
Can someone help me out here?
I am missing the -l in yout LIBS line
LIBS += -L/"C:\\test_folder\\poppler-0.24.5-win32\\lib" -lpoppler-qt5
Eventually rename the lib since .dll.a is not a standard extension in windows.
Edit: Works without renaming the library:
.pro File:
INCLUDEPATH += $$quote(D:\Users\username\Downloads\poppler-0.24.5-win32\poppler-0.24.5-win32\include\poppler-qt5)
LIBS += -L$$quote(D:\Users\username\Downloads\poppler-0.24.5-win32\poppler-0.24.5-win32\lib) -lpoppler-qt5
.cpp File:
#include <QApplication>
#include <mycpp.h>
#include <poppler-qt5.h>
/* Some Code here */
QString path = "D:\\SomePDF.pdf";
Poppler::Document *doc = Poppler::Document::load(path);
/* More Code here */
I had the same problem and I resolved it with this method:
Copy dll file if you find in folder \poppler-0.24.5-win32\bin\ to folder where Qt generate executable file. Then download zlib1.dll and insert this dll to folder where Qt generate executable file. Try now.
This works for me. I compiled with qt 5.3 in Windows XP SP3.
My IDE: Visual Studio 2010, I use Qt add-in for VS, Qt ver. 4.8.1
I have faced with the problem while trying to create precompiled header(pch) in my Qt project.
My usuall approach for creating pch in non Qt project is:
Create header;
Include files which will be precompiled in header;
For every source file in the project state in it`s properties if it will use pch;
For one source file in project state creation of pch;
Include pch in all source files.
As those action failed for Qt project I decided what it happens due to pch should be included to all files generated by MOC.
I read the article in QtAssistant on precompiled headers and did the following:
Created header file;
For all .cpp files in project set option use pch and for one create
Converted to qmake generated project
I ran qmake -project
I modified generated .pro file, here it is:
TEMPLATE = app
TARGET =
DEPENDPATH += . GeneratedFiles
INCLUDEPATH += .
PRECOMPILED_HEADER = StdAfx.h
QT += network
Input
HEADERS += server.h StdAfx.h
FORMS += server.ui
SOURCES += main.cpp server.cpp StdAfx.h.cpp
RESOURCES += server.qrc
I ran qmake
open .pro file and tried to build it and got the error:
Error 2 error C1083: Cannot open include file: 'StdAfx.h': No such file or directory
What I am doing wrong?
Create your precompiled header file and include the desired headers.
pch.hpp:
// precompiled headers
// add C includes here
#ifdef __cplusplus
// add C++ includes here
#include <iostream>
#include <QtGui>
#endif // __cplusplus
Then in your .pro file:
CONFIG += precompile_header
PRECOMPILED_HEADER = pch.hpp
HEADERS += pch.hpp
Qmake will now automatically set the correct options for the compiler.
I found solution.
The only thing needed to be done in order to use precompiled header in project is to include
the following statements in .pro file:
CONFIG += nameOfPrecompiledHeader.h
PRECOMPILED_HEADER = nameOfPrecompiledHeader.h
win32-msvc* {
PRECOMPILED_SOURCE = nameOfFileInWhichCreateOptionWillBeSet.cpp /* other .cpp files will be with use option*/
}
after .pro modification and running qmake all .cpp files will be set up for usage of pch and one for it`s creation(nameOfFileInWhichCreateOptionWillBeSet) and .pch will be generated
I'm quite a newbie with C++ and maybe that's a very stupid question, but how do one include a header from a static linked library?
I've created a static library in Qt Creator with the following .pro file:
QT -= gui
TARGET = Foobar
TEMPLATE = lib
CONFIG += staticlib
SOURCES += thefoobar.cpp \
sub/subbar.cpp
HEADERS += thefoobar.h \
sub/subbar.h
compiled it and put the resulting libFoobar.a into the "extstaticlibs" folder of my target project.
In my target projects .pro file i've added the following lines:
LIBS += -L$$PWD/extstaticlibs/ -lFoobar
INCLUDEPATH += $$PWD/extstaticlibs
The target project compiles without problems. But when I try to include the header thefoobar.h in one of my code files:
#include "thefoobar.h"
it always results in an error:
error: thefoobar.h: No such file or directory
Any suggestions for the correct syntax would be very much appreciated.
Kristoffer
Check where you have placed your "thefoobar.h" header file . Place it in the "extstaticlibs/" folder .
If I follow your description correctly, you ONLY put the static library into your extstaticlibs directory.
You need to carry over your thefoobar.h file too. If you follow the common structure you could make:
extstaticlibs/include <- thefoobar.h goes here
extstaticlibs/lib <- libFoobar.a goes here
You then need to modify your project file like this:
LIBS += -L$$PWD/extstaticlibs/lib -lFoobar
INCLUDEPATH += $$PWD/extstaticlibs/include
Of course you can all throw it in one directory, if you want, but it may be helpful to sort things out in the beginning.