Windows 10: QFileDialog::getOpenFileName(this, tr("Xml"), "c:/Users/public/documents"); opens wrong directory
-
I have the following code:
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QWidget> #include <QFileDialog> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QFileDialog::getOpenFileName(this, tr("Xml"), "c:/Users/public/documents"); } MainWindow::~MainWindow() { delete ui; }
which I expected would open a dialog in c:\users\public\documents, but instead it opens the documents
folder of the current user, namely C:\Users<username>\DocumentsIf I change the input path to a subdirectory of c:/Users/public/documents, c:/Users/public/documents/foo say,
the dialog displays the correct directory.Am I experiencing a bug in QFileDialog, or am I misunderstanding QFileDialog?
For the record, I tried the same thing through an instance of QFileDialog with the same result.
My search of this forum and through google led me to post here.
-
@nesavi said in Windows 10: QFileDialog::getOpenFileName(this, tr("Xml"), "c:/Users/public/documents"); opens wrong directory:
c:/Users/public/documents
Shouldn't it be "c:/Users/public/public documents"?
-
@jsulm said in Windows 10: QFileDialog::getOpenFileName(this, tr("Xml"), "c:/Users/public/documents"); opens wrong directory:
@nesavi said in Windows 10: QFileDialog::getOpenFileName(this, tr("Xml"), "c:/Users/public/documents"); opens wrong directory:
c:/Users/public/documents
Shouldn't it be "c:/Users/public/public documents"?
Changing the path to "c:/Users/public/public documents" opens the dialog in c:/Users/public :-)
The paths I am refering to are those written in the address bar of Windows Explorer.
-
I tried opening the same directory through a C# application, with the same results. So this is most likely not an issue related to Qt.
Thanks a lot for the replies :-)
C# code:
using System;
using System.Windows.Forms;namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { var fd = new OpenFileDialog(); fd.InitialDirectory = @"c:\users\public\documents"; fd.ShowDialog(); } } }