[solved]QFileDialog using different name filters
first of all, I'm new with QT. I started with some readings and some examples. Now I'm working on a 3D image/video viewer for distributed system. My configuration is a environment with 1 wall, 1 server and 2 clients. The server opens the image/video and sends it over network to the clients which creates the visualisation for each eye. So far my project.
I allready can open images and send them over network and display them. My problem is the QFileDialg. First I tried it with the function getOpenFileName (see below). That works fine for me until I came to the point were i tried to open videos as well. With that function I didn't find a way to see which name filter is used.
@// this filedialog uses the function, no possibility to get the selected file format
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
tr("JPG Files (.jpg .jpeg);;MPO files (.mpo);;Stereo JPEG (.jps);;3D Videos (*.avi)"));
To solve that problem I creaed a QFileDialog class and replaced the function with it (see below). I connected the signal filterSelected() with a function which saves the QString. That works fine, but the problem is the user interface. It looks now "Linux" style and it opens allways the current directory. I know I set that up at QDir::currentPath() but I couldnt find another way.
// create filename
// create fileDialog
fileDialog.setNameFilter(tr("JPG Files (.jpg .jpeg);;MPO files (.mpo);;Stereo JPEG (.jps);;3D Videos (*.avi)"));
// connect signal to change file format
connect(&fileDialog, SIGNAL(filterSelected(const QString&)), this, SLOT(setFileFormat(const QString&)));
// open file dialog
fileName = fileDialog.selectedFiles();
// check if a file is selected
Now my question, how can I get the Windows style and how can I save the last used directory. Thx so far!
regarding your first question, the extension is added to the file name, just look at that.
Regarding second question: no chance. If you create a QFileDialog object, you create the Qt implementation, The way you use the static functions tells the static function to use the native dialog.
I might mix this up with another GUI Framework, but the linux style might occur because you set the option DontUseNativeDialog.
To get the last used diectory take a look at "QFileDialog::directory()":http://doc.qt.nokia.com/4.7/qfiledialog.html#directory maybe that's what you need.
The answer is as easy as possible. I'm used to C# and there you get the information about which filter is selected and I tried it the same way with QT. Sometimes I should start thinking before coding!
If there is no other chance I just use the getOpenFileName function and search the string for the file ending!
I tried the option "DontUseNativeDialog" and there is no change
As i said, i will stick to the funtction and comparing the string.