Qt update

Dirk Hohndel dirk at hohndel.org
Tue Apr 9 09:02:27 PDT 2013


Alberto Mardegan <mardy at users.sourceforge.net> writes:

> On 04/09/2013 05:47 PM, Dirk Hohndel wrote:
>> Cool. I should have thought of that. Do you want to send a patch or
>> should I just apply it and add your Signed-off-by ?
>
> Here it is. I'm sending it to the mailing list so that more people can 
> review it (since it touches some changes made by Tomaz).
>
> Seems to work here, but please test before applying. :-)

How would I test without applying it? :-)

Or are you implying that I usually don't test the code that I push out?
I at least try...

> From c6574468ea997f080bd37c57c956bd30e80d0272 Mon Sep 17 00:00:00 2001
> From: Alberto Mardegan <mardy at users.sourceforge.net>
> Date: Tue, 9 Apr 2013 19:30:31 +0400
> Subject: [PATCH] Makefile: detect which files need moc and uic
>
> Add some magic rules to detect which files need to be processed by the
> moc or uic tools, as well as a way to manually specify exceptions.
>
> +OBJS_NEEDING_MOC =
> +OBJS_NEEDING_UIC =
> +HEADERS_NEEDING_MOC =
> +
> +# Add the objects for the header files which define QObject subclasses
> +HEADERS_NEEDING_MOC += $(shell grep -l -s 'Q_OBJECT' $(OBJS:.o=.h))
> +MOC_OBJS = $(HEADERS_NEEDING_MOC:.h=.moc.o)

So this assumes that every Q_OBJECT will have both a .cpp and a .h file.
I guess that is normal in Qt...

> +ALL_OBJS = $(OBJS) $(MOC_OBJS)

Why not just add them to OBJS?

> +
> +DEPS = $(wildcard .dep/*.dep)
>  
>  all: $(NAME)
>  
> -$(NAME): gen_version_file $(OBJS) $(MSGOBJS) $(INFOPLIST)
> -	$(CXX) $(LDFLAGS) -o $(NAME) $(OBJS) $(LIBS)
> +$(NAME): gen_version_file $(ALL_OBJS) $(MSGOBJS) $(INFOPLIST)
> +	$(CXX) $(LDFLAGS) -o $(NAME) $(ALL_OBJS) $(LIBS)
>  
>  gen_version_file:
>  ifneq ($(STORED_VERSION_STRING),$(VERSION_STRING))
> @@ -310,36 +321,33 @@ MOCFLAGS = $(filter -I%, $(CXXFLAGS) $(EXTRA_FLAGS)) $(filter -D%, $(CXXFLAGS) $
>  	@mkdir -p .dep .dep/qt-ui
>  	@$(CXX) $(CXXFLAGS) $(EXTRA_FLAGS) -MD -MF .dep/$@.dep -c -o $@ $<
>  
> -# This rule is for running the moc on QObject subclasses defined in the .cpp
> -# files; remember to #include "<file>.moc" at the end of the .cpp file, or
> -# you'll get linker errors ("undefined vtable for...")
> -# To activate this rule, you need another rule on the .o file, like:
> -#    file.o: file.moc
> +# Detect which files require the moc or uic tools to be run
> +CPP_NEEDING_MOC = $(shell grep -l -s '^\#include \".*\.moc\"' $(OBJS:.o=.cpp))

OBJS contains objects that stem from .c files as well... so this won't
work for those.

> +OBJS_NEEDING_MOC += $(CPP_NEEDING_MOC:.cpp=.o)

So now we have HEADERS_NEEDING_MOC and CPP_NEEDING_MOC but
OBJS_NEEDING_MOC only uses CPP_NEEDING_MOC. How come?
  
> -qt-ui/%.moc: qt-ui/%.h
> -	@echo '    MOC' $<
> -	@$(MOC) -i $(MOCFLAGS) $< -o $@
> +CPP_NEEDING_UIC = $(shell grep -l -s '^\#include \"ui_.*\.h\"' $(OBJS:.o=.cpp))
> +OBJS_NEEDING_UIC += $(CPP_NEEDING_UIC:.cpp=.o)

Again, what about the C files?

Wouldn't it make more sense to have

OBJS     == all object files as it used to be
QT_OBJS  == all Qt/C++ object files - those are the ones used for the
            xxx_NEEDING_yyy macros  
MOC_OBJS == object files created from .moc files created from .h files
            (do I have that right?)

> diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
> index 4569958..c630965 100644
> --- a/qt-ui/maintab.cpp
> +++ b/qt-ui/maintab.cpp
> @@ -6,5 +6,3 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
>  {
>  	ui->setupUi(this);
>  }
> -
> -#include "maintab.moc"
> diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
> index d3e5603..03e1437 100644
> --- a/qt-ui/mainwindow.cpp
> +++ b/qt-ui/mainwindow.cpp
> @@ -13,5 +13,3 @@ void MainWindow::on_actionNew_triggered()
>  {
>      qDebug() << "actionNew";
>  }
> -
> -#include "mainwindow.moc"

So all the rules above imply that we still need to do the #include on
the .moc files, yet you remove that here. Let me take a wild guess.

If the classes are defined in .h files then we don't need the #include,
but if they are defined in .cpp files then we do?

/D


More information about the subsurface mailing list