Juce.h break qt4 headers


#1

there are various serious problems with the way juce declares its namespace and some other things that it does that make it very difficult to compile with qt 4. I was making sure to include juce headers after the qt headers, and this was fine until I needed to add a precompiled header to my project, which is impossible until this is fixed.

Including juce.h before QMessageBox in a precompiled header breaks the legal QMessageBox::Button enum declaration:

c++ -x c++-header -c -pipe -g -dead_strip -Wall -W -F/usr/local/Trolltech/Qt-4.1.4/lib -fPIC  -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/mkspecs/macx-g++ -I. -I/usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/lib/QtCore.framework/Versions/4.0/Headers -I/usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/include/QtCore -I/usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/lib/QtGui.framework/Versions/4.0/Headers -I/usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/include/QtGui -I/usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/include -I../.. -I../../../libs/juce -I../../../libs/boost_1_33_1 -I../../src/gui/moc -I../../src/gui/ui ../pch/headers.h -o gui.gch/c++
/usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/lib/QtGui.framework/Versions/4.0/Headers/qmessagebox.h:62: error: 'juce::Button' referred to as enum
../../../libs/juce/src/juce_appframework/audio/devices/../../gui/components/controls/../layout/../buttons/juce_Button.h:78: error: 'juce::Button' has a previous declaration here
/usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/lib/QtGui.framework/Versions/4.0/Headers/qmessagebox.h:62: error: expected unqualified-id before '{' token
make: *** [gui.gch/c++] Error 1

Including juce.h before QList (and some others) breaks all kinds of stuff:

c++ -c -pipe -g -Wall -W -F/usr/local/Trolltech/Qt-4.1.4/lib  -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/mkspecs/macx-g++ -I. -I/usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/lib/QtCore.framework/Versions/4.0/Headers -I/usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/include/QtCore -I/usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/lib/QtGui.framework/Versions/4.0/Headers -I/usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/include/QtGui -I/usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/include -I../libs/juce -I. -I. -o test.o test.cpp
In file included from /usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/lib/QtCore.framework/Versions/4.0/Headers/qlist.h:28,
                 from /usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/lib/QtCore.framework/Versions/4.0/Headers/QList:1,
                 from test.cpp:2:
/usr/local/Trolltech/Qt-4.1.4/lib/QtCore.framework/Headers/qatomic.h:249:1: error: pasting "L" and "*" does not give a valid preprocessing token
/usr/local/Trolltech/Qt-4.1.4/lib/QtCore.framework/Headers/qatomic.h:263:1: error: pasting "L" and "*" does not give a valid preprocessing token
In file included from /usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/lib/QtCore.framework/Versions/4.0/Headers/QList:1,
                 from test.cpp:2:
/usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/lib/QtCore.framework/Versions/4.0/Headers/qlist.h:324:1: error: pasting "L" and "*" does not give a valid preprocessing token
/usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/lib/QtCore.framework/Versions/4.0/Headers/qlist.h:327:1: error: pasting "L" and "*" does not give a valid preprocessing token
/usr/local/Trolltech/Qt-4.1.4/lib/QtCore.framework/Headers/qatomic.h: In function 'void qAtomicDetach(T*&)':
/usr/local/Trolltech/Qt-4.1.4/lib/QtCore.framework/Headers/qatomic.h:249: error: 'L' was not declared in this scope
/usr/local/Trolltech/Qt-4.1.4/lib/QtCore.framework/Headers/qatomic.h:249: error: expected type-specifier before ';' token
/usr/local/Trolltech/Qt-4.1.4/lib/QtCore.framework/Headers/qatomic.h: In function 'void qAtomicDetach(QBasicAtomicPointer<T>&)':
/usr/local/Trolltech/Qt-4.1.4/lib/QtCore.framework/Headers/qatomic.h:263: error: 'L' was not declared in this scope
/usr/local/Trolltech/Qt-4.1.4/lib/QtCore.framework/Headers/qatomic.h:263: error: expected type-specifier before ';' token
/usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/lib/QtCore.framework/Versions/4.0/Headers/qlist.h: In member function 'void QList<T>::node_construct(QList<T>::Node*, const T&)':
/usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/lib/QtCore.framework/Versions/4.0/Headers/qlist.h:307: error: 'Lt' was not declared in this scope
/usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/lib/QtCore.framework/Versions/4.0/Headers/qlist.h:307: error: expected type-specifier before ';' token
/usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/lib/QtCore.framework/Versions/4.0/Headers/qlist.h:308: error: expected type-specifier before 'Lt'
/usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/lib/QtCore.framework/Versions/4.0/Headers/qlist.h:308: error: expected `)' before 'Lt'
/usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/lib/QtCore.framework/Versions/4.0/Headers/qlist.h:308: error: expected `;' before 'Lt'
/usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/lib/QtCore.framework/Versions/4.0/Headers/qlist.h: In member function 'void QList<T>::node_destruct(QList<T>::Node*)':
/usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/lib/QtCore.framework/Versions/4.0/Headers/qlist.h:316: error: expected class-name before '(' token
/usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/lib/QtCore.framework/Versions/4.0/Headers/qlist.h:316: error: 'L' was not declared in this scope
/usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/lib/QtCore.framework/Versions/4.0/Headers/qlist.h: In member function 'void QList<T>::node_copy(QList<T>::Node*, QList<T>::Node*, QList<T>::Node*)':
/usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/lib/QtCore.framework/Versions/4.0/Headers/qlist.h:324: error: 'L' was not declared in this scope
/usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/lib/QtCore.framework/Versions/4.0/Headers/qlist.h:324: error: expected type-specifier before ';' token
/usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/lib/QtCore.framework/Versions/4.0/Headers/qlist.h:327: error: expected type-specifier before 'L'
/usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/lib/QtCore.framework/Versions/4.0/Headers/qlist.h:327: error: expected `)' before 'L'
/usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/lib/QtCore.framework/Versions/4.0/Headers/qlist.h:327: error: expected `;' before 'L'
/usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/lib/QtCore.framework/Versions/4.0/Headers/qlist.h: In member function 'void QList<T>::node_destruct(QList<T>::Node*, QList<T>::Node*)':
/usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/lib/QtCore.framework/Versions/4.0/Headers/qlist.h:336: error: expected class-name before '(' token
/usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/lib/QtCore.framework/Versions/4.0/Headers/qlist.h:336: error: 'L' was not declared in this scope
/usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/lib/QtCore.framework/Versions/4.0/Headers/qlist.h: In member function 'T QList<T>::value(int) const':
/usr/local/Trolltech/Qt-4.1.4-opensource-dynamic/lib/QtCore.framework/Versions/4.0/Headers/qlist.h:477: error: 'L' was not declared in this scope
test.cpp: At global scope:
test.cpp:4: warning: unused parameter 'argc'
test.cpp:4: warning: unused parameter 'argv'
make: *** [test.o] Error 1

use the following test code:

#include <juce.h>
#include <QMessageBox> // or <Qlist>

int main(int argc, char **argv)
{
}

Thanks!


#2

This has nothing to do with namespaces - it’s macros that are causing the errors. Juce’s T() macro is obviously clashing with stuff in Qt, and on the Mac there are a few macros to definine things like Button, for compatibility with the Mac headers. Just undefining them should sort things out, e.g.

[code]#include <juce.h>

#undef T
#undef Button

#include <Qt…[/code]

If this works, or if there are one or two more things that need to be undefined, let me know, as I could create a config setting that turns off these offending macros for compatibility.

Or just include qt before juce?

Of course the real question is: why use Qt AND Juce? If they’ve got something you can’t live without, let me know and I’ll add it!


#3

Well, the following fixes the include problem, but our audio engine code (written by someone else) needs them!

#undef T;
#undef L;
#undef check;
#undef Button;
#undef Point;

Good attitude! I haven’t looked at the juce graphical API so much, but I will let you know if I can aswer such a question.


#4

Are you sure about “check” and “L”? Neither of those are mine…

If you don’t want to change your audio code to use explicit namespaces you could always just redefine the macros again after including Qt:

#define T(stringLiteral) JUCE_T(stringLiteral) #define Point JUCE_NAMESPACE::Point #define Button JUCE_NAMESPACE::Button
[/code]


#5

I’ll keep that in mind, thanks


#6

for me, the biggest drawback for juce vs qt is that juce does not have builtin native graphical look and feel.

i haven’t upgraded since 1.33 so there may be something new that i missed.

also, i’m interested in the template containers from stl as well as ‘boost’. can they exist alongside juce?


#7

That does seem to be something that people want, though I’m not entirely sure why, as I’ve always hated the native Windows look and feel. It wouldn’t be hard to write a look and feel class to do it, it’d just involve a lot of typing…

yes, no problem using both at once

And on this topic, note the new juce_WithoutMacros.h header file in v1.38 that lets you more easily solve include problems like the one this thread is about.


#8

i agree that the windows native look and feel is not as good. however, it creates a consistency across apps that makes it easier to immediately understand it’s use.

for true native look and feel, there are other implications. windows themes should be supported. also, recompiling the same app for other os’s will generate the corresponding look. finally, qt allows (with a few exceptions) the ability to specify looks to be exchanged across os’s. for example, using the mac os look on windows or (ewww) vice versa.


#9

Juce’s lookandfeel stuff is all cross-platform too, of course. It’d just be a case of writing some mac and windows lookalike classes. Not rocket science, but a bit tedious to do.


#10

No one I know uses the normal Windows theme, they all use something else (three use a Vista theme on XP, transparency and all, a couple use a black theme ala *nix’ish, I have a brushed metal theme, etc…), so a generic windows ‘looking’ theme would not be at all accurate. I like all of my apps to look like my Windows because I have Windows customized to heck and back.

Although, if I wanted consistency I’d just use Wx or what-not.


#11

i am in agreement. that is why i asked for windows theme support.


#12