Can I use Qt without qmake or Qt Creator?

后端 未结 4 1985
走了就别回头了
走了就别回头了 2020-12-04 09:50

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 com

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-04 10:24

    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
    

提交回复
热议问题