QFileDialog not showing spool folder - c++

I'm requesting the user to select a folder with QFileDialog:
QString directory = QFileDialog::getExistingDirectory(this,"Caption","",
QFileDialog::ShowDirsOnly);
I want the user to be able to select ALL folders, however C:/Windows/System32/spool/ cannot be found with the QFileDialog and i suspect there might be others.
I have tried setting the flag QFileDialog::HideNameFilterDetails in order to view hidden files, however this does not do the trick.
Is there a solution to this problem?

This appears to be a problem when you're running a 32-bit application on 64-bit Windows. You should be able to see the spool folder if you compile your application with the native x64 compiler. Worst case, you can write a simple 64-bit native app for showing the folder browser and have the 32-bit app run and communicate with the 64-bit app to get the results.
I was hoping that disabling the WOW64 File System Redirector would be enough, but it didn't help. According to this answer, it may work if you use Wow64DisableWow64FsRedirection to disable redirection on all the threads in the process but this approach is not recommended even by the person who answered the question.

You can't use that static function to see all folders. QFileDialog is doing some additional filtering behind the scenes, and that this filtering cannot be turned off in any obvious way using static function getExistingDirectory.
You can see all folders including the hidden ones by:
QFileDialog fd;
fd.setFilter(QDir::Hidden);
fd.setFileMode(QFileDialog::Directory);
fd.exec();
QString directory = fd.directory().path();

Related

Qt application has unexpected QDir::currentPath

I am using QSettings in my Qt application to store prefences and all was fine until I start to run it on Linux mint 19. Default location for settings file is application folder, but now it is creating in users home folder.
QDir::currentPath() returns home folder, if I am running application by double click, and correct executable location if I am running it from terminal. I have never seen this before. Maybe somebody knows how to fix it and run application by double click from it's own folder.
Don't depend on current working directory (returned by QDir::currentPath()), because that can be basically anything. Looks like your desktop environment's file manager sets current directory to home folder when you run software by double clicking, and this is generally sensible, because that is usually what user would want, when opening files from the app etc.
If I read correctly what you want, that is path to application folder to store settings in, you need QCoreApplication::applicationDirPath(). But note that doing this will force you to install the application to user home folder (because you can't write to system folders like /user/local/bin, and you shouldn't change this by changing permissions, either).
Based on comments, it seems QCoreApplication::applicationDirPath() gives wrong directory, but QCoreApplication::applicationFilePath() gives correct path. If that is really the case, then take the file path, and remove the executable file from it. However, looking at the Qt source, this shouldn't be possible because applicationDirPath() already does just that...
I recommend you instead use QSettings as documented in its basic usage.

How to use QFileDialog to open virtual folder

To choose the folder or file which will be deleted or created on local machine, we can use the class QFileDialog.
But my problem is, my folder or file or not exist on local machine, but on the cloud. I mean, we can create a HTTP request to get the folder structure from the cloud, but I don't know what is the easiest way to display it on GUI as a QFileDialog. How to solve this problem?
You can use QFileDialog::getOpenFileUrl to select a folder or file from a remote location.
Please note that this is not portable: Qt, when possible, will use the native file dialog, which must support selecting remote files to begin with.
The non-native dialog supports only local files, as of version 5.5.
For a portable solution, the only way I see it working is to implement your own, using a QTreeView.

How to specify a standard directory in a Qt project file

I have developed an application that I plan to deploy on Windows, Mac, and Linux. The program requires access to some files (scripts and the like) at run-time.
The installation process should install the files to a location that my application can later determine without user-intervention (or perhaps just a prompt allowing the user to change the location, if desired).
What is the best way to achieve this? I can't seem to find any way to:
1. Use a "standardized path" variable in the project file's INSTALLS statement. (e.g., my application could use QStandardPaths to initialize the location, but I can't figure out how to access this path from the INSTALLS statement)
2. Save the path to my project's QSettings (.plist, registry, whatever) for later retrieval
That leaves me with creating a custom project file and INSTALLS command for each environment, and then I still can't install to the user's directory because I don't know the user's name when I deploy the make command. It seems as if there must be a better way, but I can't seem to find any documentation for this. Am I just using the wrong keywords in my searches? Thanks in advance!
What standard directory? What type of getting that standard directory?
For instance, you can put such thing in your windows branch of .pro file:
win32 {
APPDATA_DIR = $$system(echo %APPDATA%) # should be %LOCALAPPDATA% as requested
message($$APPDATA_DIR)
}
Just unsure of what exact kind of standartized path you are talking about. QStandardPaths knows many. It makes sense to be more concrete to find the correspondence with concrete OS.
Also somewhat relative reply on mine, on how to check the correspondence with certain variable, etc: Qt .pro file - how to add conditioning on OSX version?
Maybe this class will help you
QStandardPaths documentation
But your problem is still little bit unclear for me.

Create directories anywhere in windows 7?

I have an application that requires that a DLL be able to create various directories in it's current location. However, from looking around, I have found that windows 7 apparently restricts the ability of programs to write in a lot of places. I cannot redesign the application, as the DLL is injected into a process and creates log files that the user would view. I don't want to shove them in appdata, is there any other way to do what I want?
You can try to change the current working directory with SetCurrentDirectory

How do I create a OS-neutral run configuration in Eclipse?

I would like to have a single run configuration that I can use whether I'm testing on a Windows system or a Unix system.
Everything seems to be fine with the exception that in the run configurations dialog the field for C/C++ Application requires the extension of the application as well.
So in Windows, it is: Path/To/Application.exe
and on a Unix system, it is: Path/To/Application
If there was someway to automatically detect the OS and apply the appropriate extension, I can share the same *.launch file with everyone working on the project regardless of their operating system.
I've looked a little bit into using Variables to set the path and file name, but most of them require additional dialogs and user inputs. Wild cards don't seem to work here either.
Any ideas?
Thanks to Marc K. for pointing out the quick fix of simply adding ".exe" extensions to the unix executables. Though, as he mentions, this isn't a perfect fix to the problem.