I'm using QImage.save to save an image of my OpenGL framebuffer to disk. If I just call save("plot.jpg"), I have no idea where the image ends up. It's not in the application directory. I can call save("/Users/wallacer/desktop/plot.jpg") to save the file on my desktop, but obviously that's no good for running on anyone else's machine. Is there an environment variable or something I can use to save the QImage to a known location? Or is there a way I can just save the image to the directory the application resides in?
This seems obvious, but I can't seem to find anything about choosing a save location in the docs.
Thanks!
You could use QDir::homePath or QDir::home to get a relative (and IIRC, platform independent) path.
ETA: Or the applcation's current path should be in QDir::currentPath.
Ok I feel dumb. I'm just going to use a file dialog to allow the user to select a directory to save the image file in.
Related
I have been researching a topic unsuccessfully for a couple of days. I'm a C ++ rookie, and as a practice i decided to make a basic (very very basic) copy of a version control system.
I have separated the project into steps. The first step (splited in activities) is:
The user searches, in the windows console, for the directory where the files he wants to track are located. Let's say he reached the desired path: C:\MyProjectFolder\ProjectToTrack>
Once inside ProjectToTrack folder the user applies this command: C:\MyProjectFolder\ProjectToTrack> emi track. "emi" is the name of the .EXE that i created in C ++ and the track parameter tells to the executable to create a hidden folder inside the ProjectToTrack folder.
Note: Obviously emi.exe is not in the path C:\MyProjectFolder\ProjectToTrack, let's say that emi.exe is in C:\ProgramFiles\emi\emi.exe
That's it, once this is done I will pass the second step, but I will take care of that problem later.
For now, after practicing and reviewing documentation i have achieved:
The .exe that creates a hidden folder in the path that was sent to it as a parameter, having said that ...
I also know how to send parameters to an .exe through windows console.
But, what I still can't get is:
Calling to emi.exe (C:\ProgramFiles\emi\emi.exe) through the console from any directory (necessary to track any file in any folder).
When C:\MyProjectFolder\ProjectToTrack> emi track is applied, I know how to send the parameter track to emi.exe, however, it is evident that I must also capture the current path (path i accessed from the console), so that emi.exe knows where to create the hidden trace folder; well, i still don't figure out how to capture and send this path to the main function of the .exe.
I have not found something related to what i need, english is not my default language so maybe i'm not using the correct terms, I hope that what i have said here is understandable.
PS.1. I'm currently trying to build this project using "windows.h", i would appreciate it if your comments were related to this library. Once i have understood this, I will start practicing with portability.
PS.2. I don't want a detailed solution, I just want an opinion or recommendation and maybe some links where to find what I need, I can do the rest.
Thank you!
Calling to emi.exe (C:\ProgramFiles\emi\emi.exe) through the console from any directory (necessary to track any file in any folder).
For this you need to add the folder of your executable (i.e. C:\ProgramFiles\emi) to the system global variable called PATH (both Windows and Linux work this way, and must be MAC OS as well but I never used it).
When C:\MyProjectFolder\ProjectToTrack> emi track is applied, I know how to send the parameter track to emi.exe, however, it is evident that I must also capture the current path (path i accessed from the console), so that emi.exe knows where to create the hidden trace folder; well, i still don't figure out how to capture and send this path to the main function of the .exe.
For this take a look at this STD function here: https://en.cppreference.com/w/cpp/filesystem/current_path (personally I've never used it but must be what's you're looking for).
Good luck with your endeavor!
If the user does not pass in a target path explicitly as a parameter, the EXE can use the Win32 GetCurrentDirectory() function, or in C++17 and later the standard std::filesystem::current_path() function, to retrieve its current "working directory".
If the user navigates a console window to C:\MyProjectFolder\ProjectToTrack and then executes C:\ProgramFiles\emi\emi.exe, the current working directory will initially be C:\MyProjectFolder\ProjectToTrack.
I would like to when I capture a photo with my camera it doesn't create a file in the default directory but it uses the buffer instead.
So I have set the capture destination to buffer :cameraImageCapture->setCaptureDestination(QCameraImageCapture::CaptureToBuffer)
However it still saves a file in the directory. I'm on Ubuntu 16.04. Do you have any ideas to solve my problem ? Thank you.
I'm developing an application using the Qt framework. One of the features is to get all registry from HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall using QSettings.
When I was testing, I found something curious:
My code get the path "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", in other words, QSettings registry("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall", QSettings::NativeForm), and print it to json file. Until then, it's ok. But when I open the regedit.exe and I go to the same path, the values are different. My application don't collect that information.
So I went researching and found something, windows do a redirection of this path to HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows, and that path (64bits path) apparently is inaccessible.
Anyone knows how can I get around this problem still using QSettings? Some registry, like WinRAR, are not collected because it.
Thanks, sry about the bad english.
I need to create FileSystem type of thing in memory or on disk, which can be accessed same as file on disk, which path is can be used in function like fopen(),etc.
Details:
I am using AddFontResourceEx function to load font in application. Since this function require file path so that file need to present on disk. But I've requirement, that the user cannot access/see the font file.
I tried AddFontMemResourceEx function, but the loaded font is not enumable so that user cannot see the font in the application. Also I tried with some library which create VFS, but they work like database, i.e you can create file/directory and access them. But cannot use their file path in AddFontResourceEx or any other function.
Is there exist some way by which I can create a Virtual FileSystem in memory or on disk which can be accessible through my application and I can write/read file on this virtual filesystem created and it's file path can be used by AddFontResourceEx function.
It can't really work. Yes, you can add a "virtual" file system. But either it's visible to user X or it isn't. Access Control on Windows works on a per-user base, not a per-program base. So, if user X can see the font in application A, he can also see it in application B - even if B is Explorer.EXE.
If the user is an administrator, you can't really prevent them from seeing the font file if they're determined enough. They could, for example, reverse engineer your program to figure out how you're generating the file and repeat the process by hand to make their own copy. Or (even if you could somehow tie the file permissions to your process) they could insert their own code into your process to retrieve the file, or to retrieve the font information directly from memory.
If it's good enough to make it difficult for them to see the font file, you could try this:
Create a directory in the temp folder, with write-only permission for the current user and no permissions for anyone else.
Create a sub-directory with a long, complex, cryptographically random name, and with full permission for the current user. (The name should be different each time.)
Write the font file to the sub-directory and load it.
Delete the font file and remove both directories.
The entire process should take only a fraction of a second, which should make it somewhat difficult for the user to override the permissions and retrieve the file. If they use a debugger to single-step through the program then I guess you're out of luck, but as I already pointed out, nothing's going to stop everyone.
Another option, presumably, would be to just use AddFontMemResourceEx and put up with the fact that the font isn't then enumerable. You'd just need to change your code so that wherever it enumerates fonts it adds your font(s) to the list manually.
If you didn't get the right answer, maybe you didn't ask the right question
Your post title mentions "virtual filesystem", but. later, you mention "accesing a font".
"Virtual Filesystems" its an ambiguos term used in several ways.
One common case, means adding devices or networks to an O.S.
In your case, seems like accesing from a an application.
There are several ways ( "libraries" ) to emulate or work with a filesystem.
Some of them work independent of the real filesystem. You work with them, save data in those "virtual" folders & files, and copy data from the real and the virtual one.
Some of them work, as a extension layer, between the real filesystem, and the programming filesystem.
Example: I worked with an application, that required temporally fast I.O. access. Found a library, that when you want to create a folder or save a file in the real filesystem, was done.
Additionally, I could add "virtual drives" that where stored in memory, but, accessed with file system operations. When the application finished, the "hard drives" and their data where erased from memory.
Its seems that your case is similar to my example.
What do you want a "virtual filesystem" library for ?
I have seen onb the web, several libraries, for C++, open source, freeware, and commercial.
It depends what do you want to do, to find out, which library its the better for your case.
Good Luck
Im using Magick++ Library with Qt
Im using the following code to read and write an image:
Image image;
image.read(qPrintable(f.absoluteFilePath()));
image.addNoise(GaussianNoise);
image.magick("png");
image.write("image_name");
Where f.absoluteFilePath is the absolute path for my image
Example: /Users/user/Desktop/test/P1030673.jpg
After the completion of the code, I cannot locate the image named 'image_name'.
I looked into the folder of the first image '/Users/macmini/Desktop/test/' and its not there
I tried to search the image, but it seems is not in my computer.
Where do I go wrong?
How can I save the image in my computer?
is there any way to specify the path that I want the image to be saved?
Thank you
You should find the file saved in the current working directory. If you want to save it elsewhere give an absolute path.
For everyone who might have tha same problem:
Imagemagick will save the images inside the .app bundle
You will not be able to find the image files unless you specify a path inside the read() function
I noticed the following by checking the size of my .app file
It was increased everytime I was trying to save images.