Author Topic: [Solved *Really] CodeBlock can't find QT4 libs  (Read 31549 times)

Offline sqlpython

  • Single posting newcomer
  • *
  • Posts: 7
[Solved *Really] CodeBlock can't find QT4 libs
« on: March 03, 2012, 07:37:49 pm »
   See Post #9 if you are impatiant

Hi All
 1st Post... We are attempting to migrate Qt4 work to Code::Blocks IDE.
Up until now we have worked in Qtcreator and or Codelite.
Really like the extra features of CodeBlocks and would like to use it for our QT4 projects.
We can't seem to create a working QT4 template from the Wizard.
We have attempted to effect the (qt4) Global variable in Settings.
 Experimented with Base of /usr, /usr/share/qt4
Using both of those as base then choose the appropriate sub dir for include and lib
We even tried creating a link in /usr/share/qt4 for /usr/lib
 The variable appears in the Wizard as $(#qt4)
So, we then manually typed /usr which does work but leads me wondering that w/o the variable can the include and lib dirs be located.
Once we choose /usr as the Base the Q4 Template will be made.
However if we try to build the Simple Hello World I get errors that point to the fact the #include Headers can't be located by the compiler.

Note if I was to just perform a Console project using C++ headers such as <iostream> etc not problem.
The compiler finding the QT4 libraries seem to be the problem...
 BTW:
 A base QT GUI project works in Codelite
..and of course as per it's design QTcreator works.

  We searched here and otherwise can't find a solution that works..
though we have found a number of non working suggestions...
App Test Code:
Code
 #include <QApplication>
 #include <QPushButton>

 int main(int argc, char *argv[])
 {
     QApplication app(argc, argv);

     QPushButton hello("Hello world!");
     hello.resize(200, 100);

     hello.show();
     return app.exec();
 }
Some Build errors below..
Code
/home/sqlpython/.codeblocks/Projects/HelloAgain/CodeBlockHello/main.cpp|1|error: QApplication: No such file or directory|
/home/sqlpython/.codeblocks/Projects/HelloAgain/CodeBlockHello/main.cpp|2|error: QPushButton: No such file or directory|
/home/sqlpython/.codeblocks/Projects/HelloAgain/CodeBlockHello/main.cpp||In function ‘int main(int, char**)’:|
/home/sqlpython/.codeblocks/Projects/HelloAgain/CodeBlockHello/main.cpp|6|error: ‘QApplication’ was not declared in this scope|
/home/sqlpython/.codeblocks/Projects/HelloAgain/CodeBlockHello/main.cpp|6|error: expected ‘;’ before ‘app’|
/home/sqlpython/.codeblocks/Projects/HelloAgain/CodeBlockHello/main.cpp|8|error: ‘QPushButton’ was not declared in this scope|
/home/sqlpython/.codeblocks/Projects/HelloAgain/CodeBlockHello/main.cpp|8|error: expected ‘;’ before ‘hello’|
/home/sqlpython/.codeblocks/Projects/HelloAgain/CodeBlockHello/main.cpp|9|error: ‘hello’ was not declared in this scope|
/home/sqlpython/.codeblocks/Projects/HelloAgain/CodeBlockHello/main.cpp|12|error: ‘app’ was not declared in this scope|
||=== Build finished: 8 errors, 0 warnings ===|
« Last Edit: March 06, 2012, 05:26:28 am by sqlpython »

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: CodeBlock can't find QT4 libs
« Reply #1 on: March 03, 2012, 08:59:36 pm »
I don't know where and how you "installed" QT into, but all you have to do is to adjust the QT4 global variable, that the .include tag points to where your QT's base folder for header files is (/usr/include, or /usr/local/include for example) and the .lib tag points to where the linker can find the library files (/usr/lib, or /usr/local/lib for example). As QT has changed the base folders for its libraries from major version to major version you have to understand that the (hard-coded) settings of the wizard might not match your configuration.
Another solution would be if you compile the app on the command line and then "transfer" the settings to the IDE.
That's all I can tell - again: It depends on where / how you installed QT into.

Next time please also post your full compiler log which helps to analyse what's going wrong (see my sig how to enable that).
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline sqlpython

  • Single posting newcomer
  • *
  • Posts: 7
Re: [Solved] CodeBlock can't find QT4 libs
« Reply #2 on: March 05, 2012, 04:38:23 am »
Well *Solved with an asterick....
 This solution requires that some SEARCH modifications be made to the Compiler Debugger Search setting

Solution:


Anyway my solution turned out to be to start CodeBlocks and go to Menus
Settings -> Compiler Debugger Settings -> Global Compiler Settings -> [Search Dir] Tab ->  [Compiler] subTab
.......And ADD the following dir to search
although the last 18 are sub dir of the 1st the must each be listed manually for this to work
Code
/usr/share/qt4/include/Qt  
/usr/share/qt4/include/Qt/Qt3Support
/usr/share/qt4/include/Qt/QtAssistant
.....and so on for 18 Qt subdirectories

 Lastly, You must start CodeBlocks as sudo / su user
Code
gksudo codeblocks 

AND Voila! The Qt4 apps compile....
Just I don't like running apps as sudo...
 Example, some clueless user writes an app with an rm command in it that runs without needing a sudo..
Hmmmmm....

Offline sqlpython

  • Single posting newcomer
  • *
  • Posts: 7
Re: [Solved] CodeBlock can't find QT4 libs
« Reply #3 on: March 05, 2012, 05:13:45 am »
Sorry... Posted too quickly..
THanks for the reply..
Qt4 installed in
/usr/share/qt4    per a .deb file
inside the dir is a link to
/usr/include/qt4

 I have tried early on working through the Global Variable qt4 in the settings as you suggested ... However I get this log..
Which then works if I run CodeBLocks as Root user..


Code
-------------- Build: Debug in QtFixed ---------------

g++ -Wall  -g    -I/usr/include -I/usr/include/QtGui  -c /home/sqlpython/.codeblocks/Projects/QtFixed/QtFixed/main.cpp -o obj/Debug/main.o
/home/sqlpython/.codeblocks/Projects/QtFixed/QtFixed/main.cpp:1:24: error: QApplication: No such file or directory
/home/sqlpython/.codeblocks/Projects/QtFixed/QtFixed/main.cpp:2:17: error: QFont: No such file or directory
/home/sqlpython/.codeblocks/Projects/QtFixed/QtFixed/main.cpp:3:23: error: QPushButton: No such file or directory
/home/sqlpython/.codeblocks/Projects/QtFixed/QtFixed/main.cpp: In function ‘int main(int, char**)’:
/home/sqlpython/.codeblocks/Projects/QtFixed/QtFixed/main.cpp:7: error: ‘QApplication’ was not declared in this scope
/home/sqlpython/.codeblocks/Projects/QtFixed/QtFixed/main.cpp:7: error: expected ‘;’ before ‘app’
/home/sqlpython/.codeblocks/Projects/QtFixed/QtFixed/main.cpp:9: error: ‘QPushButton’ was not declared in this scope
/home/sqlpython/.codeblocks/Projects/QtFixed/QtFixed/main.cpp:9: error: expected ‘;’ before ‘quit’
/home/sqlpython/.codeblocks/Projects/QtFixed/QtFixed/main.cpp:11: error: ‘quit’ was not declared in this scope
/home/sqlpython/.codeblocks/Projects/QtFixed/QtFixed/main.cpp:12: error: ‘QFont’ has not been declared
/home/sqlpython/.codeblocks/Projects/QtFixed/QtFixed/main.cpp:12: error: ‘QFont’ was not declared in this scope
/home/sqlpython/.codeblocks/Projects/QtFixed/QtFixed/main.cpp:14: error: ‘QObject’ has not been declared
/home/sqlpython/.codeblocks/Projects/QtFixed/QtFixed/main.cpp:14: error: ‘clicked’ was not declared in this scope
/home/sqlpython/.codeblocks/Projects/QtFixed/QtFixed/main.cpp:14: error: ‘SIGNAL’ was not declared in this scope
/home/sqlpython/.codeblocks/Projects/QtFixed/QtFixed/main.cpp:14: error: ‘app’ was not declared in this scope
/home/sqlpython/.codeblocks/Projects/QtFixed/QtFixed/main.cpp:14: error: ‘SLOT’ was not declared in this scope
Process terminated with status 1 (0 minutes, 0 seconds)
15 errors, 0 warnings
 

Offline sqlpython

  • Single posting newcomer
  • *
  • Posts: 7
Re: [Solved] CodeBlock can't find QT4 libs
« Reply #4 on: March 05, 2012, 05:23:40 am »
Ok... Thank You..
I believe you have now pointed me in the correct direction which allows me (based on all the above info) to have the compiler find the QT4 libs running Code::Blocks as my User and not root user.

I just had to find the correct combination of dirs referenced by variable qt4

In the Code::Blocks Settings -> Globalvariables
Choosing to effect in the pop up window the variable qt4
I list the dirs this way...which compiles and works
the dirs are added this way including quotes  " "
  Remember all that read this my qt4 deb installed to   /usr/share/qt4/

base  "/usr"

nclude "/usr/share/qt4/include"

lib  "/usr/lib"

obj  "/usr/bin"
« Last Edit: March 05, 2012, 06:22:56 am by sqlpython »

Offline sqlpython

  • Single posting newcomer
  • *
  • Posts: 7
Re: [Solved] CodeBlock can't find QT4 libs
« Reply #5 on: March 05, 2012, 06:25:22 am »
Arrggghhh
Spoke too soon!!

 Seems that the User Launched version of CodeBlocks cannot First Compile the Project..
If the Project is first Built by the root launched version then the user launched version can later Build/Run the projects. However if Rebuilt by the User launched version the same problems as the above log ensue..

Any Thoughts?

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: [Solved] CodeBlock can't find QT4 libs
« Reply #6 on: March 05, 2012, 06:36:04 am »
No code, no help. However, this:
Code
-------------- Build: Debug in QtFixed ---------------
g++ -Wall  -g    -I/usr/include -I/usr/include/QtGui  -c /home/sqlpython/.codeblocks/Projects/QtFixed/QtFixed/main.cpp -o obj/Debug/main.o
..doesn't look good to me. -I/usr/include/QtGui should not be needed.

As I still don't fully understand your system layout (did you really install the QT-DEV package?) its hard to suggest any setup.

Why don't you first try to compile on the command line and then transfer to the IDE? Notice that you also don't need to use global variables - if they are too hard to understand in the first place, just include what's needed as usual, using the path directly in the compiler/linker options.

Notice that here:
http://wiki.codeblocks.org/index.php?title=Global_compiler_variables
...and here:
http://www.codeblocks.org/docs/main_codeblocks_en3.html#x3-1020003.7
...you'll find more information.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline sqlpython

  • Single posting newcomer
  • *
  • Posts: 7
Re: [Solved] CodeBlock can't find QT4 libs
« Reply #7 on: March 05, 2012, 11:35:39 pm »
 Thanks for your input....
This is a bit frustrating...Please be aware that I am an IDE user since 1985 beginning with my Days using Borland products..
I have never to my memory ever had problems installing compiler dir lib location in Windows nor Linux.
....Currently I can run the same code in QtCreator as well as Codelite without issue..
Also I can convert the code with pyuic and then run against the same lib with PyQt in Eric and Spyder IDEs w/o issue..
.....only Code::Blocks rejects the paths...and or libs as User yet works as Root/Super user..
Anyhow, I completely uninstalled Code::BLocks cleaned out dirs and Reinstalled Code::Blocks.....
Once again entered my References to the Compiler directive for the $(#qt) variable...
as above the same directories...

So I started the Default QT project via the Wizard..
All went well until the compile...
Code::Blocks now throws up errors by opening up the config file in the Qt lib sub dir...
It reads the file in the QtGui /include/QtGui/ dir
This runs an if clause which runs through the dir contents as Check of contents to present the libs to compiler inquiries..
It begins like so.... and goes on to run through the contents of the dir...
There are 18 Qt sub dir and each one has one of these ref files

Code
#ifndef QT_QTGUI_MODULE_H
#define QT_QTGUI_MODULE_H
#include <QtCore/QtCore>
#include "qabstractitemdelegate.h"
#include "qabstractitemview.h"
#include "qabstractproxymodel.h"

  This file is then opened on the editor next to main.cpp..
and an error is throw on the 3rd line not finding <QtCore/QTCore>  as a dir so I tried <QtCore> as the second item is a file not a dir... But no help then drills into the qcoreapplication.h and disagrees with some contents there.... [out of breath]

I am about read to accept that Code::Blocks is not Qt4 compatible.. I have searched the forums here and I see Qt4 setup issues going back to at least 2006 without any satisfactory solution..
Here is my dir tree if it gives you any ideas...
  Thanks for patience...

Code
sqlpython@debian7:/usr/share/qt4$ ls
bin  include  phrasebooks  q3porting.xml  translations
doc  mkspecs  plugins      QtCore
sqlpython@debian7:/usr/share/qt4$ tree -d /usr/share/qt4/include
/usr/share/qt4/include
├── Qt
├── Qt3Support
├── QtCore
├── QtDBus
├── QtDeclarative
├── QtDesigner
├── QtGui
├── QtHelp
├── QtNetwork
├── QtOpenGL
├── QtScript
├── QtScriptTools
├── QtSql
├── QtSvg
├── QtTest
├── QtUiTools
├── QtWebKit
├── QtXml
└── QtXmlPatterns

19 directories

sqlpython@debian7:/usr/share/qt4$ tree -d /usr/include/qt4
/usr/include/qt4
├── Qt
├── Qt3Support
├── QtCore
├── QtDBus
├── QtDeclarative
├── QtDesigner
├── QtGui
├── QtHelp
├── QtNetwork
├── QtOpenGL
├── QtScript
├── QtScriptTools
├── QtSql
├── QtSvg
├── QtTest
├── QtUiTools
├── QtWebKit
├── QtXml
└── QtXmlPatterns

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: [Solved] CodeBlock can't find QT4 libs
« Reply #8 on: March 06, 2012, 12:47:22 am »
The solution I use for Qt4 is to adjust the priority of compilation. Every header file containing the Q_OBJECT macro has to have a higher priority of compilation with the moc compiler and then u can include the 'moc.cpp' file in the corresponding .cpp file. That works for me.

Offline sqlpython

  • Single posting newcomer
  • *
  • Posts: 7
Re: [Solved] CodeBlock can't find QT4 libs
« Reply #9 on: March 06, 2012, 03:14:11 am »
Thanks for your Input that can work.....
But...
We FINALLY have automated the solution Globally.....
  Working with my Brother my fellow programmer he has come upon the method to GLobally declare a series of Dirs that will work when Code::Blocks is run as USER...
  He Has been working day and Night to come upon the solution but during this time his Wife and Children have left him!!!!
(However he now has Peace and Quiet)
This is the Global automated solution add to Compiler Search Global All QT dirs and /usr/share/qt4/include.....
Anyway the solution turned out to be to start CodeBlocks and go to Menus
Settings -> Compiler Debugger Settings -> Global Compiler Settings -> [Search Dir] Tab ->  [Compiler] subTab
.......And ADD the following dir to search
although the last 18 are sub dir of the 1st they must each be listed manually for this to work as well as /usr/share/qt4/include...

Also recommend that you modify the Global Variable as follow
I just had to find the correct combination of dirs referenced by variable qt4

In the Code::Blocks Settings -> Globalvariables
Choosing to effect in the pop up window the variable qt4
I list the dirs this way...which compiles and works
the dirs are added this way including quotes  " "
  Remember all that read this my qt4 deb installed to   /usr/share/qt4/

base
 "/usr"

include
"/usr/share/qt4/include"

lib "/usr/lib"

obj  "/usr/bin"
« Last Edit: March 06, 2012, 03:31:17 am by sqlpython »

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: [Solved *Really] CodeBlock can't find QT4 libs
« Reply #10 on: March 06, 2012, 11:06:39 pm »
Well on Win I don't remember bugging the settings that much, must be specific to linux.

huhmaster

  • Guest
Re: [Solved *Really] CodeBlock can't find QT4 libs
« Reply #11 on: September 26, 2012, 07:12:47 am »
What is the final solution guys ?  ??? ???
Here is what I did but I am still getting the same error as " fatal error: QtCore/QByteArray: No such file or directory| "
Similar errors for all other include files.

1. In the Code::Blocks Settings -> Globalvariables


base  "/usr"

include "/usr/share/qt4/include"

lib "/usr/lib"

obj  "/usr/bin"

2. Settings -> Compiler Debugger Settings -> Global Compiler Settings -> [Search Dir] Tab ->  [Compiler] subTab
and added all 18 directories in /usr/share/qt4/include/
That didn't work so I tried the 18 directories in /usr/include/qt4/

Stilll nothing is working.
Need a solution urgently guys.   ???  :'(

Offline Radek

  • Multiple posting newcomer
  • *
  • Posts: 104
Re: [Solved *Really] CodeBlock can't find QT4 libs
« Reply #12 on: September 26, 2012, 09:59:15 am »
I have given up a combination Code Blocks + Qt4 long ago but I have a recommendation:

(1) Add only one #include path, namely /usr/share/qt4/include.
(2) Include headers along with their subdirs. Supposing QApplication is in QtCore (I don't know), #include <QtCore/QApplication> and not #include <QApplication>. Well, you need to know exactly where your headers are but they won't be in too many subdirs. This should solve the problem with Qt4 headers.
(3) If you can compile only as a root then check access rights of the directories of the headers, the headers themselves and Qt4 libraries for access rights. You need rwxr-xr-x everywhere. If it is not the case, update access rights (as a root). You will do it only once.
(4) More problems ahead: MOC compiler, etc. Good luck  ;D

You can also create a script, say qt4-config, which will push the needed include paths and libpaths on the command line. Then you add `qt4-config` to the compiler and linker options. It's a similar practice as the one used by wxWidgets (wx-config).

ars

  • Guest
Re: [Solved *Really] CodeBlock can't find QT4 libs
« Reply #13 on: March 30, 2015, 02:13:40 am »
I have defined the global variable at win xp, CB 10.05, qt 4.8, includeed include folders in compiler options of CB,. But I father receive "Qdir not found" about header file--what to do to resolve this issue?