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 .
Related
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 creating an installer and I need to have functionality to read a text file and get some installation params. Specifically, I need to read an installation path from a text file. I was trying to use FileReader from JS, but I can't figure out how it could be used inside the Controller.prototype.TargetDirectoryPageCallback function. Maybe there is easier approach to do that? Any working sample maybe?
The script context has only a few objects.
console
QFileDialog
print
qsTr
systemInfo
QInstaller
buttons
QMessageBox
QDesktopServices
installer
gui
The "installer" object is the most important one (see http://doc.qt.io/qtinstallerframework/scripting-installer.html#execute-method).
With the help of this execute method you can run any application on your system. So here my untested code suggestion:
if (installer.value("os") == "win") {
var windir = installer.environmentVariable("WINDIR");
if (windir == "")
print("Could not find windows installation directory.");
var cmdLocation = windir + "\\system32\\cmd.exe";
var fileContent = installer.execute(cmdLocation, new Array("/c", "type", <your_file>))[0];
Yes this is not very comfortable - so maybe you should create a feature request or add this kind of functionality to the installer framework.
Qt Installer Framework 3.x:
string readFile(string filePath, string codecName)
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 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)
I've been trying to figure out how to programmatically add files to an Xcode4 project and it seemed like AppleScript would be the way to go, however I'm running into "missing value" errors.
Here's the code I've got:
tell application "Xcode"
set theProject to first project
set theTarget to first target of theProject
set theBuildPhase to compile sources phase of theTarget
tell first group of theProject
set theFileRef to make new file reference with properties {full path:"/Users/jeff/Projects/XcodeTest/XcodeTest/MyViewController.h", name:"MyViewController.h", path:"XcodeTest/MyViewController.h", path type:group relative}
add theFileRef to theProject
end tell
--tell theBuildPhase to make new build file with properties {build phase:theBuildPhase, name:"MyViewController.h", file reference:theFileRef, target:theTarget, project:theProject}
end tell
I've tried the commented-out line instead of the add-command as well, but that doesn't work either (I get "missing value").
The 'add' error is:
error "Xcode got an error: file reference id \"251AD3431432472E006E300F\" of Xcode 3 group id \"251AD32C14324645006E300F\" of project \"XcodeTest\" of workspace document \"XcodeTest.xcodeproj/project.xcworkspace\" doesn’t understand the add message." number -1708 from file reference id "251AD3431432472E006E300F" of Xcode 3 group id "251AD32C14324645006E300F" of project "XcodeTest" of workspace document "XcodeTest.xcodeproj/project.xcworkspace"
The "make new reference" does add the file to the list of files in Xcode, but I also need it to be added to the project target so that I can add actions and outlets to the file from Xcode w/o having to first check the checkbox to add it to the "target membership".
I ended up sending this question to the devs on the xcode developer list and the response I got was effectively "you can't".
This appears to be completely broken in Xcode4, but I've seen a project that does it. I think what they are doing is parsing and modifying the "project.pbxproj" file directly. (this file is hidden inside the xcodeproj bundle)
The file is a GUID soup, but once you look at it for a while it seems possible to safely modify it, especially if you are only adding stuff.
Edit:
Found this stackoverflow answer that might help.
Tutorial or Guide for Scripting XCode Build Phases
There is a poorly documented user defined build setting that can be added. Files can be both excluded and included from compilation
Go to your target's Build Settings > Tap the + button > Add User-Defined Setting
The key is either INCLUDED_SOURCE_FILE_NAMES or EXCLUDED_SOURCE_FILE_NAMES
The value is a space separated list of file paths
See reference:
http://lists.apple.com/archives/xcode-users/2009/Jun/msg00153.html