QT creator : Adding folder for .cpp & .h filers - c++11

I work for a big project and i would like to put all .cpp & .h files in one folder . I did that in .pro file :
SOURCES += src/main.cpp src/test.cpp
HEADERS += src/test.h
The problem that in QT creator the files was in Headers>src>test.h and not in Headers>test.h directly .

Qt Creator visualizes the build system. In qmake there is a huge difference in how headers and sources are handled. That's why Creator keeps them separate.
How should Creator keep all the headers in a flat out when they are stored in a tree? That makes little sense IMHO. People usually group files in folders for a reason.

I would like that in the file system the .h & .cpp files put together in one folder
You have to implement it yourself by modifying your copy of Qt Creator.
I don't know why the default behavior [...]
... because different people have different preferences, and the entire world doesn't think the same.

Related

ATMEL Studio adding own library

I tried to add my USART library to my project but I am still failing to properly add it so it will be recognized.
I created an USART.c and USART.h file, which I want to add. This is what I tried:
1) Right Click on the Solution / Properties / Toolchain / Directories
2) Adding the Path where I got these two files
When I try to build the project, it did not work. I get the message undefined reference to 'initUSART'.
How do I add my own libraries to projects then?
The screenshot in your question shows that you arranged for the compiler to find the header files for your library. But you also need to use the compiler to compile your library functions (e.g. initUSART) and create a static library file (with a lib prefix and a .a extension). You would need a separate Atmel Studio project for that, or learn how to use the AVR GCC toolchain outside of the IDE to compile libraries. Then you need to put that file in a directory that is in the linker's search path for libraries, and then you need to pass the appropriate -l argument to the linker. For example, if your library is called libuart.a, you need to pass -luart to the linker. The Project Properties for an Atmel Studio project has the relevant settings you need to configure.
GCC has a standard way to compile, create, and link to static libraries, which I outlined above. You can learn about that from any tutorial on GCC static libraries. You then would need to apply that knowledge to the AVR GCC toolchain, and find the appopriate options inside Atmel Studio that you need to set.
Aside: Atmel Studio does not make it easy to use libraries at all. The Arduino IDE does a much better job because you just put the source files for the library in the right place and it compiles them for you. There are a huge number of Arduino libraries too; you wouldn't have to write your own UART driver if you could use the Arduino platform.
The simple alternative: If you don't know much about compiling and linking to C libraries and configuring your IDE, you would have a much easier time just copying the library files into your project, adding them as source files, and letting Atmel Studio compile them just like any other source file in your project.
Another simple way of adding folders to your project is to copy/paste the folder into your project and then open Atmel Studio.
On the right side (where is by default Solution Explorer) you'll see all your files except the ones that you just added. Now press the Show all files and search for you folder which should appear grayed out. Right click on it and Include in project. That should be all!
This image should help
I got another solution that might help . i found Include Directories in this path for MegaAvr(8bit) :
C:\Program Files (x86)\Atmel\Studio\7.0\packs\atmel\ATmega_DFP\1.6.364\include
Just Puts All your Library in one Folder And Copy All of It in this path , then include it like another library . For example I created a folder named "ali" in that path , then i copied all my libraries in this folder (like alcd.h , usart.h) and then included in my programes with this :
#include <ali/usart.h>
and done ! just remember to backup your folder before Windows Installation (Drive Format) . Also you can find your libraries (.h and .c) in Solution Explorer -> Dependencies after Code Compilation .
GoodLuck ...
inside Folder
including xio.h in folder ali
xio.h in dependencies after compilation
my folder in specified path

Why I can't see .rc files in Qt Creator?

I have an open-source project successfully compiled using Qt Creator on a Ubuntu (Trusty) OS which I am trying to customize.
The problem is that even if in the project itself (on my machine) I can see .rc files, in the Qt tree view those files doesn't appear.
Why is this happening and how can I modify / add those .rc files to my project ? There are probably more than 100 resource files so adding them manually (if possible) is not a solution.
UPDATE 1:
I can't seem to find it
As an important note, you should know that this is just an imported project which is compiled / built & runned using QT Creator.
Make sure your .pro includes something like
OTHER_FILES += your_file_name.rc
as with any other file, you must reference those files in the project file to include them. Of course, this will only show your_file_name.rc in the tree view.

Best practice for using same source files in multiple projects in Qt Creator

I would like to use the same header and source file in multiple, closely related projects. Qt creator allows to have multiple projects open in the Projects bar, and it allows to "Add existing files". I can add source files from an other project to my current project, it appears nicely in the tree structure, but I can't #include them. The compiler just can't find them, even if they are included in the project. I even looked into the .pro file, and they appear there, with a relative path.
What is the best practice? If possible, I would like to avoid using any paths, even relative ones in the #include s in my source files, so the actual location of all the files would only be in the project file and nowhere else.
You can add include-file search paths in the .pro file like this:
INCLUDEPATH += ../MyIncludeFilePath0 F:/MyProj/MyIncludeFilePath1 etc.

Qt, CMake, Visual Studio and Q_OBJECT in cpp files

I'm developing a large project using Qt 4.6, CMake 2.8 and Visual Studio 2008 for the Windows platform.
As far the build system goes, it's all standard stuff: I'm using CMake's QT4_WRAP_CPP macro to generate moc files from header files, which are then linked into the final executable in the add_executable command. Everything is working as expected.
The only restriction with this setup is that I can't define widgets or helper using Q_OBJECT in .cpp files. This would be very convenient for small, context-specific helpers classes that should appear right next to where they're used.
I tried to pass the whole list of source files (both .h and .cpp) to QT4_WRAP_CPP, instead of just the header files, but that doesn't work (linking fails because some moc-related symbols are undefined).
I think the problem is that, for a given pair of files foo.h and foo.cpp, the QT4_WRAP_CPP macro will generate the same moc file (moc_foo.cxx) in the same directory, and obviously that means the first file will be overwritten by the second one, and as a result symbols will be missing at link-time.
Is there a way to fix or work around that problem? For instance, I tried to add a specific rule for foo.cpp of the form
QT4_GENERATE_MOC(directory/foo.cpp directory/foo.moc)
and then add
#include "foo.moc"
at the end of foo.cpp. I think this ought to work, but alas Visual Studio only allows one build rule per file, and .cpp files already have a build rule (compilation to object file), so this approach doesn't work, at least with Visual Studio.
Another idea that I had was to create a new macro, say QT4_WRAP_CPP_WITH_PREFIX, based on QT4_WRAP_CPP (which is defined in share/cmake-2.8/Modules/Qt4Macros.cmake), that would take an additional prefix argument and would add this prefix to the generated moc files. That way, I would call QT4_WRAP_CPP_WITH_PREFIX twice, once for .h files and once for .cpp files, with different prefixes. What I just dislike about this approach is that I'd be messing with the internals of CMake's Qt support, instead of using the public API.
Any better idea?
Recent versions of CMake have "automoc" which worked like a charm for me:
http://blogs.kde.org/2011/11/01/cool-new-stuff-cmake-286-automoc
Simply add in the CMakeLists.txt:
set(CMAKE_AUTOMOC TRUE)
and then in the cpp (e.g. example.cpp) file:
#include "example.moc"
(the *.moc must match the cpp file's name).
Referring to the documentation "Using the MOC" (http://doc.qt.nokia.com/4.1/moc.html), you'd only need to import "foo.moc" at the end of your implementation file. As you can not tweak the build rules correspondingly, try to export a .pro file and apply the build rule as suggested by the nokia document.

How should I structure my Qt based project so as to have a clean qmake generated xcode project?

If I add sources and headers in my .pro file that arn't in the same directory, the resulting xcode project groups the files by it's default Sources, Headers, etc. but then puts the files in a subdir of those folders indicating the subdirectory where the files are. This make non-flat projects look exceedingly ugly when generated for xcode (notice all the Qt examples are flat).
How do I prevent it from doing that? Or am I stuck with either an ugly xcode layout, or a flat project?
You can create your own configuration features for qmake by adding a new CONFIG argument variable in a .prf file.
Check out this Qt wiki.
Also it looks like you can use different variable names to generate different group names in xcode.
I'm going to figure out both these methods and generate a nice report.

Resources