I am making a project in QT Creator 2.6. I am promoting a QWidget subclass called cPlotter, but when I try to compile the project, it fails because it cannot find the file cplotter.h. I figured out that this is because the file “ui_mainwindow.h” updates automatically including the file cplotter.h within brackets instead of quotes.
So, ui_mainwindow.h updates like:
#include < cplotter.h >
but it should be:
#include “cplotter.h”
So, it is very annoying to edit by hand every time I change something on the GUI.
Anyone knows a solution for this?
INCLUDEPATH += $$PWD
(or where cplotter.h)
Related
In the premake lua script for my solution. How do i set it to create "/Yc" the phc instead of being set to use "/Yu" on first initialisation.
I have searched the online documentation and tried other help sites. I can't find any help.
I assume it's a build option but have tried buildoptions { "/Yc" }
Some help would be much appritiated?
The solution was to set the correct path to the source file.
premake5.lua
pchheader "awepch.h"
pchsource "%{prj.name}/Src/awepch.cpp" // this is where the source file is located on disk
* Also it is mandatory that you use the correct case for the characters. If you use "pch.h" for a file name on disk that must be the file name in this section of your "premake5.lua" script
Sorry to take so long to deliver the answer :)
you need to specify
pchheader('StdAfx.h')
and
pchsource('StdAfx.cpp')
For the current version of premake v5. 0.0-beta1, you must do the following in order for the precompiled header to work across all IDEs (especially for Visual Studio):
Put both pch.h and pch.cpp under the root directory of your project (not solution/workspace).
Set the exact name (not a path) of the pch.h to pchheader().
Set the full path of pch.cpp relative to premake5.lua script in pchsource(). This is IMPORTANT. I don't know why, but if you do not specify the full relative path, then premake will Use (/Yu) (use precompiled header) to the phc.cpp instead of Create (/Yc) (create precompiled header), which results in not creating the precompiled header in Visual Studio.
Include the directory where pch.h and pch.cpp are located in includedirs()
#include "pch.h" IN EVERY .cpp file in your project, IN THE FIRST LINE of each .cpp file. Remember: #include "pch.h", "pch.h" must be excactly the same as the string you set in pchheader() in your premake5.lua script.
If you have .c files, you MUST rename them to .cpp instead, otherwise Visual Studio will complain about using a precompiled header that was compiled using a c++ compiler.
I know it's overcomplicated but this is how it is.
Example:
project "LearnGL"
location "Projects/LearnGL/"
kind "ConsoleApp"
language "C++"
targetdir "builds/"
objdir "obj/%{prj.name}_%{cfg.shortname}"
pchheader "pch.h" --Do not use paths here. Use directly the header file name
pchsource "Projects/LearnGL/src/pch.cpp" --Full path MUST be specified relative to the premake5.lua (this) script.
files {
"Projects/LearnGL/src/**.h",
"Projects/LearnGL/src/**.hpp",
"Projects/LearnGL/src/**.cpp"
}
includedirs {
"Projects/LearnGL/src/", --This is where pch.h and pch.cpp are located.
"Projects/LearnGL/src/external/glad/include/",
"Projects/LearnGL/src/external/stb_image/include/",
"External/glfw/include/",
"External/spdlog/include/"
}
I am importing 2 QML files that come with Qt Controls - ScrollBar.qml and Button.qml in my project. I pre-compile all .qml files that I wrote to reduce application launch time. Is there a way to pre-compile these 2 QML files that come as part of the package?
I tried to remove these files from the qml/QtQuick/Controls/ path and placed them in the same folder as my .qml files but it still failed to load. When I reference ScrollBar in my code, it always tries to load ScrollBar.qml from qml/QtQuick/Controls/ path.
Does any one know if it is possible to pre-compile these QMLs at all? If yes, has any one successfully done it?
Appreciate any help. Thank you.
I'm assuming that you're referring to the Qt Quick Compiler as pre-compiling. The simplest way would just be to build the entire Qt Quick Controls module with the Qt Quick Compiler.
If you need to have it within your project, you could try adding an import that contains the Qt Quick Controls import. QQmlEngine::addImportPath() says:
The newly added path will be first in the importPathList().
That statement seems to imply that order matters, and the code confirms it:
QStringList localImportPaths = database->importPathList(QQmlImportDatabase::Local);
// Search local import paths for a matching version
const QStringList qmlDirPaths = QQmlImports::completeQmldirPaths(uri, localImportPaths, vmaj, vmin);
for (const QString &qmldirPath : qmlDirPaths) {
QString absoluteFilePath = typeLoader.absoluteFilePath(qmldirPath);
if (!absoluteFilePath.isEmpty()) {
QString url;
const QStringRef absolutePath = absoluteFilePath.leftRef(absoluteFilePath.lastIndexOf(Slash) + 1);
if (absolutePath.at(0) == Colon)
url = QLatin1String("qrc://") + absolutePath.mid(1);
else
url = QUrl::fromLocalFile(absolutePath.toString()).toString();
QQmlImportDatabase::QmldirCache *cache = new QQmlImportDatabase::QmldirCache;
cache->versionMajor = vmaj;
cache->versionMinor = vmin;
cache->qmldirFilePath = absoluteFilePath;
cache->qmldirPathUrl = url;
cache->next = cacheHead;
database->qmldirCache.insert(uri, cache);
*outQmldirFilePath = absoluteFilePath;
*outQmldirPathUrl = url;
return true;
}
}
Your project structure might look something like this:
myproject/
qml/
main.qml
QtQuick/
Controls/
Button.qml
ScrollBar.qml
qmldir
In main.cpp you'd set the path to the qml directory (note that the path will be different depending on whether you're doing an in-source build or a shadow build of your project, so you may want to use a resource file to simplify things):
engine.addImportPath("path/to/qml");
Note that the controls import other types. For example, Button uses the Settings singleton, which comes from the QtQuick.Controls.Private import, so you'd need to copy that into the qml directory, too. Settings loads a certain style for the button (ButtonStyle), which could be any of the styles in this folder, depending on which style is in use.
In short, you need to copy all of the potential dependencies of the QML files you're using.
I'm making an application part of which is reading from an XML which stores some preferences. However, whenever I build the project, all the sources get copied but the preferences file does not! I have added the following to the .pro file -
RESOURCES += rsc.qrc
And my rsc.qrc contains
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>data/preferences.xml</file>
<file>data/gamedata.xml</file>
</qresource>
</RCC>
Now whenever I try to open preferences.xml
QFile preferences(":/data/preferences.xml");
if(!preferences.exists()){
preferences.open(QFile::WriteOnly);
preferences.write("abc");
qDebug() << "Written";
}
else {
qDebug() << "File exists";
}
Absolutely nothing gets printed and even the rest of the application stops working.
You don't use the resource part correctly in your example.
It will most likely not work because you try to write to a resource that is embedded into your executable after you have build your application. Reading is fine, but writing can't work by definition.
If you want a editable setting files, you have to distribute them along with your executable, or use a different method for reading/writing your settings like QSettings.
However using QSettings also means, that you will need to configure all your default settings in your loading function in case the values do not exist if you use the default configuration. Meaning you use registry on windows.
You have the option to force the use of a INI file format in the constructor of QSettings, this can make sense if you want to provide a default settings INI file instead of your xml files.
In case you want to store more complex data a xml file might be needed anyway, so if you want to stick with that you will need a way to copy your setting files to your build path. This can be done within your pro file with QMAKE_POST_LINK.
Example:
COPY_CMD = "$$PWD\\data\\preferences.xml $$OUT_PWD\\release\\data\\preferences.xml"
COPY_CMD = $${QMAKE_COPY} $$replace( COPY_CMD, "/", "\\" ) $$escape_expand( \\n\\t )
QMAKE_POST_LINK += $$COPY_CMD
I'm using QtCreator to develop a larger application which is set up as .pro files with the SUBDIRS template.
Some of the sub projects need to include the generated ui_*.h files from other sub projects (e.g. in order to extend a generic GUI class). Each sub project has a line like
UI_DIR = gen/ui/$${CONFIGURATION_NAME}
where CONFIGURATION_NAME is "static_debug" or "static_release".
Now what I usually do is add the following includes when necessary:
#if _DEBUG
#include <OtherProject/gen/ui/static_debug/ui_SomeClass.h>
#else
#include <OtherProject/gen/ui/static_release/ui_SomeClass.h>
#endif
However, this does not work when shadow building, as the generated files are in the shadow build folder while the source files are in the source folder.
Is there a way to make this work with shadow builds, or is there a more sophisticated way to handle such cases in general?
The SUBDIRS template is an awesome feature although not documented well enough I think.
Here's a link from the Qt wiki which is of help in this case: http://qt-project.org/wiki/QMake-top-level-srcdir-and-builddir
To re-cap a bit:
Qt4-based solution
myproject.pro
TEMPLATE = subdirs
SUBDIRS = initvars.pro subdir1 subdir2 #subdir1 and subdir2 are your project subdirs
initvars.pro
TEMPLATE=subdirs
SUBDIRS= # don't build anything, we're just generating the .qmake.cache file
QMAKE_SUBSTITUTES += .qmake.cache.in
\.qmake.cache.in
top_srcdir=$$PWD
top_builddir=$$OUT_PWD
Qt5-based solution
Here things get easier
top_srcdir=$$PWD
top_builddir=$$shadowed($$PWD)
Now, having access to the actual build dir, your subprojects will go in the relevant subdirs. You can use this information to fill in the INCLUDEPATH in your subprojects .pro files to make it easier to include what you need from your sibling projects.
I personally have not had this problem but the problem could be arising because
It’s probably looking for them in current dir.Take a look at how you
include the ui_.h files in your headers.Add UI files path to qmake’s includepath.
You can change where to create them using the UI_DIR variable in
your .pro file.
I have qtcreator 5 and I want to use the libpng12-0 library.
I don't know how I have to link into my project ?
There's a problem when I writte:
loadedimage = IMG_Load(filename.c_str());
I know that I have to writte something like:
LIBS += -L
LIBS += -libpng12-0
Does anyone know what I have to do ?
I tried a lot of things but I'm new on qt creator 5. Thanks for help.
Sorry for my english.
If you need a GUI method then,
Open .pro file
Right click any where in text editor area
Choose Add Library
Then choose the type of library
Provide the path of the library file
Done.
If you directly want to edit .pro file, then library name will be -lpng12-0 not -libpng12-0 .