Can I use Qt without qmake or Qt Creator?

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

Leave a Comment