Including images and a file to a project - c++

I m having some images that I load from some paths C:/....png to display them in a user interface, and a file that I would like to insert whithout specifying everytime its path
I tried to include images in my project and access them directly without specifying their addresses, especially that I would work on many machines and I don't want to change the path everytime, and create folders and images again. It didn't work!
I use a QPixmap to load images and have access to the image like what is follow:
QPixmap image("C:/images/image.png");
Even if I include that file to the project (image.png), when doing
QPixmap image("image.png");
the image is not found and pixmap is having nothing.
As for the file, it's a text file that I would like to insert to the project. "myFile.txt" which exits at:
C:/images/myFile.txt
Any ideas how to resolve that?

I recommend using Qt's resource system. It allows you to store the images inside the executable, which is usually more convenient than having a lots of files alongside the executable.

Related

Set OSM config options using API and not the global config file

When reading OSM files using GDAL, the fields that are read are defined in osmconf.ini, and if I want that certain tags don't appear within the other_tags then I need to add them to the attributes value in the corresponding sections.
This works fine, but is not really portable, so my questions is, is there a ways to define the settings saved in osmconf.ini in a portable way per project?
This is possible using the CPLSetConfigOption function, and store the config file in current working directory:
CPLSetConfigOption("OSM_CONFIG_FILE", "osmconf.ini");

Get app icon URL in Qt on Linux

I am trying to get the icon of an app (doesn't matter which one). I noticed Qt doesn't have something like GDesktopAppInfo and therefore I tried getting it through QSettings from /usr/share/applications/appname.desktop. That's already a problem, because the desktop file might not be there. Anyway, going further to extract the Icon key. Now I dunno how to find the url (notice that I need the url, sure I could make a QIcon, but I need to export it to QML, which would mean another QQuickImageProvider class, anyway, I don't wanna go that way). Is it possible, or is the aforementioned QQuickImageProvider my only solution?
Here is a little guide that might help you find your way. Keep one thing in mind: start with the basic case, get code running and extend it to more difficult cases later.
For now, lets assume the following:
.desktop file is in /usr/share/applications
App icon is in SVG or PNG format
App icon path is absolute
App name is lower case and does not contain whitespace
Input: App name "git-cola"
Read /usr/share/applications/git-cola.desktop
Use a QRegularExpression to get the Icon value
You get an absolute iconPath, e.g. /usr/share/git-cola/icons/git.svg
Have an invokable C++ function that exposes a QUrl to QML
In QML, set the source property of an Image to getIconUrl("Target App")
where 4. looks something like
QUrl MyClass::getIconUrl(QString appName)
{
// get iconPath from appName
return QUrl::​fromLocalFile(iconPath);
}
If things are running, you can add support for
Multiple .desktop locations (there might be a handful or so)
Add support for relative paths
Add support for XPM files
You can use QIcon::fromTheme(QString iconName) to find the icon. It works most of the time but it's not as reliable as gtk

virtumart product thumbnail image not showing

http://lumene-iran.com/index.php?option=com_virtuemart&view=category&virtuemart_category_id=2&Itemid=177
What is wrong that my image is not showing up? It is OK in local host but when I upload it, it doesn't show up! I checked that image path is correct in localhost but in the above URL I don't know why but the image path has changed!
Buddy , you need to change the image path in the virtuemart in configuration/templates tab.
You are seeing it on the local because it has taken your local images folder which is in the root (images/virtuemart), but when you move the files to server the path is different one, So you need to change the path in your server too.
one more thing i have seen your source code your include 26 css files which is huge, you need to compress them.
Hope I am clear with my question, let me know if you still don't get the images after changing the path.

File downloader suggestions

I need to provide non-techie user ability to reliable download a few large files (3Gb) from URL without revealing the source URL of the file. Ideally I need single exe (without dependencies) that will download file from URL, specified inside exe: when user click on exe it just need show prompt where to save the file, and(optionally) will provide the user with some progress bar, for instance. The target URL can be specified directly in
the resource section, so I can edit URL path with HEX editor when I need set another path.
Wget are not suitable in my case, as its command line utility and requires user to specify an URL.
You could use the URLDownloadToFile function. Implement the IBindStatusCallback interface to receive progress information.
You really can't hide the source URL. Why are you trying to do that? If an end user runs tcpdump while they are running your program, they'll see where packets are coming from and going to.
I'd just provide them with a small batch file which calls ftp.exe. Tell your end user to drop the .BAT file where the downloaded file should go, and click it.
That solves quite a few problems, e.g. you know that your end user will be able to find the directory.

How to combine the working directory with a user specified file (w or w/o path) to get the up-dir of the file

at the moment I'm writing a kind of lib, which gets from outside the file name 'sFilename'. With it data were written to a file it will be created, data were append to an existing file with data, data were updated in an existing file with data or the data were read from an existing data.
The user of the application with my lib should get as much as possible on information about errors of file handling.
For this purpose I code a method FileExists(...) which uses _stat() to determine if a file exists or not and a method "bool checkPermission(std::string sFilename, CFile::EOpenmode iOpenmode)" which gives back a bool if the specified file (sFilename) with the iOpenmode (Read, Write, Readwrite) have the permission to be read, written or read and written.
This method works with _stat(sFilename.c_str(), &buf) too and gives the desired information of the file back in buf.
Before checking any file I want to check if the directory containing the specified file has the desired permissions and for that I want to use the checkPermission method [works with _stat()] for the directory!
Now the problem: how can I determine easyly the containing directory? If the user just give a filename "test.txt" the file will be created or read in working directory. So its easy to get the up-directory. Its the same like the working directory. (And there its simple to use checkPermission to get detailed information about the directory).
But what about when the user not only give the file name? For exaample "....\test.txt" or "dir1\dir2\test.txt". How to combine the working directory with a specific path to gain the up-directory of the file and then to check the permissions?
Phew, I hope all is clear and it was'nt too long ;-)
Rumo
I'd suggest using the Boost FileSystem library at www.boost.org. In particular, check out the path class, which has methods such as make_absolute and parent_path.
This is Windows example code GetFileNameFromHandle to show you how to get the path from a HANDLE. I think it is what you are looking for.
http://msdn.microsoft.com/en-us/library/aa366789%28v=vs.85%29.aspx
I found out that _stat() and _access() doesn't really works for the permissions of the directories. See this stackoverflow page.
With _stat() you can't use ".\" to get information about the current directory. But _access() at least can check if a directory exists as well ".\" or "..\".
In conclusion I use _access() to check the existence of a directory and _stat() to check the permissions of an existing file. If a file should be created I'll check it by doing.
And by the way ;-) I don't need to combine working directory with the user specified file because I can use the specified file alone in _access() to determine if directory exists.
Rumo