Qt VS Tools Generating Incorrect MOC Command - qt

I've been struggling all afternoon to track down an issue with the Qt VS Tools in Visual Studio 2013. I'm trying to update an existing .vcxproj file that used a home-grown mechanism for generating MOC, UIC, etc. files to use the Qt VS Tools mechanism instead.
The problem I'm having is in the MOC command that's getting generated for .h files that include the Q_OBJECT macro. A sample line (reduced for brevity) is here:
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" "-I$(QTDIR)\include\QtGui" "-I$(NOINHERIT)"</Command>
The problem is that NOINHERIT doesn't exist, so the "-I$(NOINHERIT)" gets evaluated to "-I" without a value, and the MOC compiler complains and doesn't generate the MOC file. I've tried cleaning up inherited paths, checking and unchecking the "Inherit from parent or project defaults", and the only change I sometimes see is that it has "-I" without the NOINHERIT macro.
Completely starting over with a new .vcxproj file is beginning to feel like my only hope, but that's a much larger task than I'd like to take since there's a significant number of them with interdependencies that I'd rather not create again.
I'm using the latest Qt VS Tools, which is version 2.3.2. Any ideas on how to resolve this?

Naturally, five minutes after I post, I found the issue. An included property file had this:
<AdditionalIncludeDirectories></AdditionalIncludeDirectories>
Rather than this, which solved the problem:
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
Interestingly, and for what it's worth, this did not work:
<AdditionalIncludeDirectories />

Add the %(AdditionalIncludeDirectories) at project->C/C++ -> General -> Additional Include Directories.
%(AdditionalIncludeDirectories) is added by default, but if for some reason, this is overwrite by mistake, then we will get an error as such.
Moc'ing XXXXXXX.h...
Missing value after '-I'.

Related

qmake's write_file() and system() doesn't want to make a file

I've got a strange behavior of qmake while trying to write smth to another file. I read all possible manuals and searched out the internet but found nothing similiar. Closer to the simplest possible code:
!system(echo 1 > d:\1.txt) {
warning(Cant create a file)
}
It doesn't create a file, and it doesn't show a warning, that means that operation succeded. Another example:
var = test string
file = $$absolute_path(d:\1.txt)
message(Variable: $$var and filename: $$file)
!write_file($$pathBat, pathtowrite) {
warning(Cant create a file)
}
This block produces output:
Project MESSAGE: Variable: test string and filename: d:/1.txt
And nothing is said about the fact the file has not been created.
I've already checked the rights to write to the directory: everything seems fine.
Can anybody help me with this?
UPD:
I've found something else: message($$system(echo 1 > 1.txt)) works fine. And this is what makes me cry, because I really don't understand what is going on.
Huh! I found the solution and it may sounds like buy yourself some brain. I thought, that qmake is launched every time the project file is changed (output of message commands proved my thoughts), but it's not really the way things happen in Qt.
I don't know how exactly, but it parses the .pro file, does only some necessary operations, and as I can see system() (which is going to change some file), write_file() commands doesn't seem to be invoked.
The SOLUTION is so much simple: natively launch qmake using the Build - Launch qmake.

Inheriting forms in Qt with CMake (multiple inheritance method)

I imagine this is fairly straight-forward, but I admit I'm not well-versed in CMake (or Qt for that matter), so here's the problem:
I have a form that was built in Qt Designer (with a .ui file). Two classes have been created that are based on this form. Both classes have a lot of duplicated code. So, I wanted to create a base class that inherited the formname.ui file using the multiple inheritance method to manage that common code.
The problem is that I don't know how to get CMake to build it correctly. Compiling gives me the error ui_formname.h: No such file or directory.
I've identified the following elements as necessary to get CMake to buld this correctly:
set (UI_HDR ${CMAKE_SOURCE_DIR}/path/to/formname.ui)
QT4_WRAP_UI (COMPONENT_UI_HDR ${UI_HDR})
include_directories(${CMAKE_CURRENT_BINARY_DIR}) #Necessary here?
The difference between this and the other two cases is that this cmakefile is not building an executable, whereas in the other two cases, it was. It may be I'm missing something else, but the lack of an add_executable line is the most obvious difference that I can see, as the COMPONENT_UI_HDR variable would be included in that list, were it there.
Any suggestions on how to work around that?
Solved the problem. Indeed, I was right about the "add_executable" difference. Since this was a library and not an executable, I had to add a reference to the wrapped variable in the add_library call, i.e.:
add_library ( ${...} ${COMPONENT_UI_HDR} )
Compiled without a hitch...

Using CMakes qt_wrap_ui command

I'm currently trying to change the build system used for a QT project from Visual Studio to CMake and I'm having trouble figuring out the correct usage of the qt_wrap_ui command. Currently, I'm using it like this:
macro(addQtForProject argLibraryName argSourceList)
...
qt_wrap_ui(${argLibraryName} ${argSourceList} ${argSourceList} ${varUiList})
endmacro()
As I handle the source and headers as a single list, I of course want the generated files to end up in the same list. varUiList contains the four .ui files used by the project.
When using CMakes visual studio 2005 generator with this macro, it adds four .h files, one for each .ui file, to the Visual Studio project file but the files themselves does to seem to exist at all so I must be doing something wrong. CMakes documentation is unfortunatly fairly sparse on this subject. This has been tested with CMake 2.8.10.
You probably want to use the more recent FindQt4 module which has much more documentation.
Specifically, it provides the QT4_WRAP_UI macro:
QT4_WRAP_UI(outfiles inputfile ... OPTIONS ...)
create code from a list of Qt designer ui files.
Options may be given to uic, such as those found
when executing "uic -help"

GNAT Programming Suite: Cross-Reference Info Not Up To Date (this is a guess)

I'm trying to get package references resolved during a build, using GNAT Programming Suite (hosted on Win XP). In the Builder Results, I get errors like this one:
file "ac_configuration_s.ada" not found
Clicking on the error takes me to a line like this:
with
Ac_Configuration,
Dispense_Timer,
...
The first item (Ac_Configuration) isn't resolved, but the second item (Dispense_Time) is resolved. I have several others that do or don't resolve. All of the files in question (spec and body) are identified as source files.
When I hover my mouse over the line with the error, a popup shows up that offers this:
(Cross-references info not up to date. This is a guess.)
Ac_Configuration
local package declared at D_Ac_Config_S.Ada:85
The guess is correct, but I don't know how to use this. How do I get this to correctly build?
Update
Here is teh call to gcc
gcc -c "-gnatec=C:\Source\build\GNAT-TEMP-000001.TMP" -I- -gnatA
-x ada "-gnatem=C:\Source\build\GNAT-TEMP-000002.TMP" "C:\Source\C_Cbt_Main_B.Ada"
I don't see a reference to teh "miimal" switch.
In this case, there is no corresponding body file file D_Ac_Config_S.Ada. So the is no body file to compile separately.
When I right click on the package reference inside the with, I can goto the declaration of Ac_Configuration and every other package name that is the source of an error. So these lreferences are being resolved somehow.
By the way, I have not used ADA before, so I'm still trying to understand everything.
It looks as though you're using _s.ada as the suffix for specs, and I'm guessing _b.ada for bodies?
GNAT may have difficulty with this naming convention. It's possible, using a GNAT Project file (.gpr), to alter GNAT's default convention ({unit-name}.ads for specs, {unit-name}.adb for bodies) but the rules (see "Spec_Suffix") say "It cannot start with an underscore followed by an alphanumeric character" (I haven't tried this, but you can see that it would confuse the issue if you had a package Foo_S, for example).
LATER: It turns out that GNAT (GPL, 4.7, 4.8) is quite happy with your suffixes!
If the package Ac_Configuration is really a local package declared at line 85 of D_Ac_Config_S.Ada, then there's your problem; you can only with a library unit, which in this case would be D_Ac_Config.
with D_Ac_Config;
...
package Foo is
...
Bar : D_Ac_Config.Ac_Configuration.Baz;
I wonder whether D_Ac_Config_S.Ada (for example) actually contains multiple Ada units? (if so, compiling that file should result in a compilation error such as end of file expected, file can have only one compilation unit). GNAT doesn't support this at compile time, providing instead a utility gnatchop.
Would it be possible to just gnatchop all the source and be done with it?
Hm, I think it sounds like the compiler's got a bad set of objects/ALIs it's working with, hence the cross-reference not up to date error. (Usually the compiler's good about keeping things up to date; but you may want to check to see if the "minimal recompilation" switch is set for the project.)
Have you tried compiling just the ["owning"] file D_Ac_Config_S.Ada? (i.e. if it were a spec, go to the corresponding body and compile that.) That should force its ALI/object files to be updated.
Then try building as normal.
-- PS: you might have to clean first.

How does one compile single file Xcode 4?

While I used to compile a single source file with Cmd+K in prior versions of Xcode, how does one do the same in Xcode 4? (Note that this is different than preprocessing or showing the disassembly of the file.) If compiling from a command line is proposed then it must be such that the project's settings, include paths, preprocessor definitions, etc., are all included.
An example use case is where I make a header file change but only want to test the change's effect with respect to a single source file, not all of the files that depend upon that header.
The command has been moved to the Perform Action submenu. Look under
Product > Perform Action > Compile filename.cpp
To assign Cmd+K to it, go to
File > Preferences > Key Bindings > Product Menu group
and you'll find Compile File where you can assign a key. Cmd+K is assigned to Clear Console now by default, so be sure to remove that binding to avoid conflicts.
One way that I have found to do this is to using the following menu commands:
Product -> Generate Output -> Generate Preprocessed File
Product -> Generate Output -> Generate Assembly File
This may not be exactly what you want, but it will compile the single file.
When you build a project, xcode runs compilation command. You can check the log, search for your file and copy paste that command on Terminal. It'll compile only the file for which you copy/pasted on the terminal.
If your file is C (or C++) file, then simply open your terminal, go to the folder in which the file resides and type
gcc -o outputFile inputFile.c
I am not familar with Objective-c that much, but GCC might work since it's only a superset of C, just like C++.
Hope that was helpful :)
The keyboard shortcut Cmd+K on Xcode 3 and before has been remapped to Cmd+B on Xcode 4
Along the same lines, Cmd+Return was remapped to Cmd+R (in case you ever used that)
The common requirement for single file compilation is checking it for syntax errors. (atleast for me). Since xcode4 highlights syntax errors as you type. It seems apple removed that feature.

Resources