Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to program using Qt, but I don't want to use special compilers or IDE such as Qt Creator and qmake. I want to write with Kate and compile with g++.

Can I compile a program that uses Qt with g++? How do I compile it with g++?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
425 views
Welcome To Ask or Share your Answers For Others

1 Answer

Sure you can. Although it is more convenient with qmake or CMake, you can do:

CXXFLAGS += -Ipath_to_your_qt_includes
LDFLAGS += -Lpath_to_your_qt_libs

LDLIBS += -lqt-mt (for Qt3)

or

LDLIBS += -lQtCore -lQtGui (for Qt4, add what you need)

my_prog: my_prog.cpp

(in a makefile)

Update - invoking moc:

Quote from moc manpage:

Here is a useful makefile rule if you only use GNU make:

m%.cpp: %.h
        moc $< -o $@

I'd personally name the output rather %.moc.cpp (than m%.cpp). You then add the dependency of my_prog on my_prog.moc.cpp

my_prog: my_prog.cpp my_prog.moc.cpp

Similarly for uic. The situation here is more complicated, since you have to generate rules for headers and source files, and you have to add a dependency on a header file to ensure it gets generated before the sources are compiled. Something like this might work:

my_prog: my_prog.o my_prog.moc.o my_prog.ui.o
        $(CXX)  $(LDFLAGS) -o my_prog $^ $(LDLIBS)

my_prog.o: my_prog.cpp my_prog.ui.h

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...