Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Custom build steps for QT ui and moc file
Custom build steps for QT ui and moc file [message #812260] Sat, 03 March 2012 13:56 Go to next message
Hauke Krüger is currently offline Hauke KrügerFriend
Messages: 7
Registered: March 2012
Junior Member
Hi,

I have just turned to Eclipse from Visual Studio. Now, I would want to compile the MS VC source code using Eclipse. Compiling and linking *.cpp and *.h files works pretty good but in the next step I want to use QT and hence UIC and MOC to generate some *cpp/*.h code in a CUSTOM BUILD STEP.

On Visual Studio, I define a custom build step with the following entries (example for UIC):

Description="Uic'ing "$(InputPath)" to produce "$(InputDir)\ui_$(InputName)".h" CommandLine=""$(QT_DIR)"\bin\uic.exe "$(InputPath)" -o "$(InputDir)\ui_$(InputName)".h
Outputs=""$(InputDir)\ui_$(InputName)".h"

In Eclipse, I can import the *.ui file to my project. Then I can right click on the *.ui file to setup the properties for a custom build step as I did in Visual Studio. Finally, I select "Settings->Build Steps" to enter very similar entries in the Eclipse/CDT control window:

Output File Names: $(InputDir)\ui_$(InputName)".h
Command: \usr\bin\uic.exe "$(InputPath)" -o "$(InputDir)\ui_$(InputName)".h
Description: Uic'ing "$(InputPath)" to produce "$(InputDir)\ui_$(InputName)".h

Once finished with this procedure, nothing happens when I try to execute the custom build step. This is how I try to envoke the custom build steps:

Variant a) Right clicking the *.ui file, I can see the "Build Selected File(s)" option but it is inactive and can hence not be clicked (Build Automatically is disabled).
Variant b) Building the complete project: The custom build step is not executed as part of the make process. I would expect at least some hint that anything related to the defined custom build step happens, presumably followed by an error message due to the VS variables such as "InputName", but this is not the case.

So, what is the trick to execute this custom build step? Which build variables such as InputName/InputPath in Visual Studio are defined in Eclipse? What do I have to do to "activate" my custom build steps?

Thanks for any help and best regards,

HK
Re: Custom build steps for QT ui and moc file [message #813064 is a reply to message #812260] Sun, 04 March 2012 20:00 Go to previous messageGo to next message
Hauke Krüger is currently offline Hauke KrügerFriend
Messages: 7
Registered: March 2012
Junior Member
Additional information:

If I add the *.ui file with the custom build steps as described, the next "save" of the Eclipse workspace even seems to corrupt the complete Eclipse workspace:

What did I do:
1) I create the project which contains *.cpp and *.h files
2) I add the UI file with the specified custom build steps
3) I exit Eclipse and thereby save the workspace
4) I restart Eclipse with the workspace used before
5) When compiling any project, I get a NullPointer exception
6) Going to "project properties" -> "C/C++ Build" -> "Settings", nothing is displayed, instead, the message "The currently displayed page conatins invalid values.".

I wonder, did the feature with the custom build steps ever work?

By the way, I use

Eclipse IDE for C/C++ Developers
Version: Indigo Service Release 2
Build id: 20120216-1857

Best regards

HK

Re: Custom build steps for QT ui and moc file [message #813475 is a reply to message #813064] Mon, 05 March 2012 10:11 Go to previous messageGo to next message
Axel Mueller is currently offline Axel MuellerFriend
Messages: 1973
Registered: July 2009
Senior Member
Quote:
Output File Names: $(InputDir)\ui_$(InputName)".h
Command: \usr\bin\uic.exe "$(InputPath)" -o "$(InputDir)\ui_$(InputName)".h

You have to use different variables for Eclipse like ${selected_resource_name} etc.

But I would advise you to use qmake from Qt to generate the Makefile for you.


Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: Custom build steps for QT ui and moc file [message #813522 is a reply to message #813475] Mon, 05 March 2012 11:20 Go to previous messageGo to next message
Hauke Krüger is currently offline Hauke KrügerFriend
Messages: 7
Registered: March 2012
Junior Member
Hi,

thank you for the response. Well, I would like to use these Eclipse specific variables but I did not find a definition of the available variables. The build steps I cited is specific for the Visual Studio environment only and I hope that there is an equivalent for each Variable in Eclipse. Maybe you know a good link in which these variables are defined?

Regarding QT: I could indeed use qmake for this problem, however, the example for the *.ui and the *.moc files were only presented to clarify the problem. I need these custom build steps for moc and uic code generation as well as for my own tools to generate code. And in that case, _.ui and *.moc files could be handled in the same way as my own code templates.

By the way, I have started to take a look at CMake to solve this issue but I would like to work in a way similar as I do with MS Visual Studio and avoid the effort to lear CMake.

Best regards

HK
Re: Custom build steps for QT ui and moc file [message #813562 is a reply to message #813522] Mon, 05 March 2012 12:38 Go to previous messageGo to next message
Axel Mueller is currently offline Axel MuellerFriend
Messages: 1973
Registered: July 2009
Senior Member
Quote:
Maybe you know a good link in which these variables are defined?

That's the best link I have found (besides the Eclipse source code)
http://publib.boulder.ibm.com/infocenter/rsahelp/v7r0m0/index.jsp?topic=/org.eclipse.cdt.doc.user/reference/cdt_u_mprop_macros.htm

You can also get a list of variables (and a description for some of them) when you open Project Properties->C/C++ Build: Builder settings and click the button Variables (to activate this button you have to disable "Use default build command").


Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: Custom build steps for QT ui and moc file [message #814232 is a reply to message #813562] Tue, 06 March 2012 07:39 Go to previous messageGo to next message
Hauke Krüger is currently offline Hauke KrügerFriend
Messages: 7
Registered: March 2012
Junior Member
Thank you very much for that link. That is very helpful for me.

Best regards
Re: Custom build steps for QT ui and moc file [message #814493 is a reply to message #812260] Tue, 06 March 2012 14:12 Go to previous messageGo to next message
Hauke Krüger is currently offline Hauke KrügerFriend
Messages: 7
Registered: March 2012
Junior Member
Hi,

now - thanks to the given link - I have figured out what the problem is: The custom build step only fires if the output file is a *.cpp file. If I specify a *.h file, the custom build step is ignored. And the output file which is specified is - it seems that this is a must - directly compiled.

I wonder: Is that really the intended behavior? It seems so different to what I am used to with Visual Studio.. Is there a way to work around this behavior?

And by the way: Setting up a custom build step for my resource file (*.ui) corrupts my Eclipse workspace also in Windows. Is Eclipse + CDT really ready to be used as is in a professional way or is it common to work around these annoying bugs by using CMake?

Best regards

HK


Re: Custom build steps for QT ui and moc file [message #814614 is a reply to message #813522] Tue, 06 March 2012 17:15 Go to previous messageGo to next message
Axel Mueller is currently offline Axel MuellerFriend
Messages: 1973
Registered: July 2009
Senior Member
I was wrong with my assumption about variables. You have to use Makefile syntax. You can see your custom build step in the file subdir.mk in the Debug/src folder.
You have to insert the following:

Select Apply Custom Build Step

Output filename:
ui_%.h

Command:
/usr/bin/uic $< -o $(@)

Then you have to create a make target (Build of ui file seems not to work. I don't kno why).
Open the file subdir.mk and in the Outline View select src/ui_test.h (in my test case it was test.ui) then open context menu and choose Add Make Target. You can then call this make target in the make target view.


Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: Custom build steps for QT ui and moc file [message #815480 is a reply to message #814614] Wed, 07 March 2012 18:19 Go to previous messageGo to next message
Hauke Krüger is currently offline Hauke KrügerFriend
Messages: 7
Registered: March 2012
Junior Member
Hi,
thank you again for your help!

I did as you said (I created another new workspace with a C++ project):

1) Add *.ui to my project
2) Right-click on the *.ui file, "add custom build step", Output filename as you said, command as you said.
3) I managed to create the make target. I was confused to give this make target a name, I used "uifiles"
4) I opened the subdir.mk and found the entry for my ui-file!
5) I finally found the Outline View and did as you said.
6) Afterwards, I also could "make" the new target (hence, everything is good up to here).
7) I get a "NullPointerException".
8 ) I quit Eclipse and restarted Eclipse
9) My workspace is broken, all modifcations have gone.

In the outline view, I also got the Java callstack:

java.lang.NullPointerException
at org.eclipse.cdt.managedbuilder.internal.core.AdditionalInput.needsRebuild(AdditionalInput.java:336)
at org.eclipse.cdt.managedbuilder.internal.core.InputType.needsRebuild(InputType.java:1619)
at org.eclipse.cdt.managedbuilder.internal.core.Tool.needsRebuild(Tool.java:3307)
at org.eclipse.cdt.managedbuilder.internal.core.ResourceConfiguration.needsRebuild(ResourceConfiguration.java:854)
at org.eclipse.cdt.managedbuilder.internal.core.ResourceConfiguration.setRebuildState(ResourceConfiguration.java:869)
at org.eclipse.cdt.managedbuilder.internal.core.ResourceConfiguration.addTool(ResourceConfiguration.java:495)
at org.eclipse.cdt.managedbuilder.internal.core.ResourceConfiguration.<init>(ResourceConfiguration.java:119)
at org.eclipse.cdt.managedbuilder.internal.core.Configuration.<init>(Configuration.java:419)
at org.eclipse.cdt.managedbuilder.internal.dataprovider.ConfigurationDataProvider.load(ConfigurationDataProvider.java:366)
at org.eclipse.cdt.managedbuilder.internal.dataprovider.ConfigurationDataProvider.loadConfiguration(ConfigurationDataProvider.java:541)
at org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager.loadData(CProjectDescriptionManager.java:1115)
at org.eclipse.cdt.internal.core.settings.model.CConfigurationDescriptionCache.loadData(CConfigurationDescriptionCache.java:95)
at org.eclipse.cdt.internal.core.settings.model.CProjectDescription.loadDatas(CProjectDescription.java:196)
at org.eclipse.cdt.internal.core.settings.model.xml.XmlProjectDescriptionStorage.loadProjectDescription(XmlProjectDescriptionStorage.java:486)
at org.eclipse.cdt.internal.core.settings.model.xml.XmlProjectDescriptionStorage.getProjectDescription(XmlProjectDescriptionStorage.java:231)
at org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager.getProjectDescriptionInternal(CProjectDescriptionManager.java:416)
at org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager.getProjectDescription(CProjectDescriptionManager.java:398)
at org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager.getProjectDescription(CProjectDescriptionManager.java:393)
at org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager.getProjectDescription(CProjectDescriptionManager.java:386)
at org.eclipse.cdt.make.ui.MakeContentProvider.getSourceEntries(MakeContentProvider.java:400)
at org.eclipse.cdt.make.ui.MakeContentProvider.getChildren(MakeContentProvider.java:103)
at org.eclipse.cdt.make.ui.MakeContentProvider.hasChildren(MakeContentProvider.java:169)
at org.eclipse.jface.viewers.AbstractTreeViewer.isExpandable(AbstractTreeViewer.java:2127)
at org.eclipse.jface.viewers.TreeViewer.isExpandable(TreeViewer.java:588)
at org.eclipse.jface.viewers.AbstractTreeViewer.isExpandable(AbstractTreeViewer.java:2153)
at org.eclipse.jface.viewers.AbstractTreeViewer.updatePlus(AbstractTreeViewer.java:2835)
at org.eclipse.jface.viewers.TreeViewer.updatePlus(TreeViewer.java:852)
at org.eclipse.jface.viewers.AbstractTreeViewer.createTreeItem(AbstractTreeViewer.java:834)
at org.eclipse.jface.viewers.AbstractTreeViewer$1.run(AbstractTreeViewer.java:808)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at org.eclipse.jface.viewers.AbstractTreeViewer.createChildren(AbstractTreeViewer.java:782)
at org.eclipse.jface.viewers.TreeViewer.createChildren(TreeViewer.java:644)
at org.eclipse.jface.viewers.AbstractTreeViewer.createChildren(AbstractTreeViewer.java:753)
at org.eclipse.jface.viewers.AbstractTreeViewer.internalInitializeTree(AbstractTreeViewer.java:1533)
at org.eclipse.jface.viewers.TreeViewer.internalInitializeTree(TreeViewer.java:833)
at org.eclipse.jface.viewers.AbstractTreeViewer$5.run(AbstractTreeViewer.java:1517)
at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1443)
at org.eclipse.jface.viewers.TreeViewer.preservingSelection(TreeViewer.java:403)
at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1404)
at org.eclipse.jface.viewers.AbstractTreeViewer.inputChanged(AbstractTreeViewer.java:1510)
at org.eclipse.jface.viewers.ContentViewer.setInput(ContentViewer.java:280)
at org.eclipse.jface.viewers.StructuredViewer.setInput(StructuredViewer.java:1690)
at org.eclipse.cdt.make.ui.views.MakeView.createPartControl(MakeView.java:144)
at org.eclipse.ui.internal.ViewReference.createPartHelper(ViewReference.java:375)
at org.eclipse.ui.internal.ViewReference.createPart(ViewReference.java:229)
at org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReference.java:595)
at org.eclipse.ui.internal.WorkbenchPage$ActivationList.setActive(WorkbenchPage.java:4317)
at org.eclipse.ui.internal.WorkbenchPage$18.runWithException(WorkbenchPage.java:3359)
at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run(StartupThreading.java:31)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3563)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3212)
at org.eclipse.ui.application.WorkbenchAdvisor.openWindows(WorkbenchAdvisor.java:803)
at org.eclipse.ui.internal.Workbench$33.runWithException(Workbench.java:1600)
at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run(StartupThreading.java:31)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3563)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3212)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2609)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
Hint for 5) I do not remember the error message but due to 6)-9), I can not reproduce it.

Do you also see the problem with the corrupted workspace? I have tested this on Linux and Windows, in both cases, workspace is corrupt once editing the custom build steps. This seems to be the most problematic issue now..

Best regards

Hauke

[Updated on: Wed, 07 March 2012 18:36]

Report message to a moderator

Re: Custom build steps for QT ui and moc file [message #815963 is a reply to message #815480] Thu, 08 March 2012 09:12 Go to previous messageGo to next message
Axel Mueller is currently offline Axel MuellerFriend
Messages: 1973
Registered: July 2009
Senior Member
I did not get a corrupted workspace but I played a little bit more with these custom build steps. Unfortunately, the results are very disappointing. It does not work as expected (build selected file does not work at all) and the solution with the make target is not very user friendly (you have to create such a make target for every *.ui file and then call it).
IMHO, I would advise you to forget about the custom build steps as it does not work reliable. You should create a Qt *.pro file and then use qmake to generate you makefile. There is a Qt plugin for Eclipse from Nokia which will help you to create this *.pro file (or you create it manually it is not very difficult). With the use of qmake you would be independent of the IDE, i.e. you can use one *.pro file to create a Makefile for Eclipse and a vcproj file for Visual Studio. That's what we are using at our company successfully (and I guess most Qt users use either qmake or cmake to generate the Makefile/VC project file).


Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: Custom build steps for QT ui and moc file [message #816382 is a reply to message #815963] Thu, 08 March 2012 19:41 Go to previous message
Hauke Krüger is currently offline Hauke KrügerFriend
Messages: 7
Registered: March 2012
Junior Member
OK, so that is a clear statement even though it is not what I hoped for.
Thank you very much for taking the time to help me!

Best regards

Hauke
Previous Topic:Cannot open shared object file libstdc++.so.6
Next Topic:Eclipse C/C++ and OpenCASCADE Libraries problem
Goto Forum:
  


Current Time: Fri Apr 19 22:01:57 GMT 2024

Powered by FUDForum. Page generated in 0.04026 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top