QFileDialog opens a second (possibly parent) unwan

2019-02-26 01:32发布

Probably this issue is due to not defining parent widget properly. In QT manual or examples available online, first argument passed to QFileDialog::getOpenFileName (or similar functions) is generally "this". In my case, if I call following function with "this", it will open the dialog box and another window that doesn't contain anything and has a title which is the same as the name of executable file. I tried to get rid of the second unwanted window with no success. I replaced "this" with "gui::parentWidget()" or "0", still same issue. Also if I remember correctly I didn't have this issue before updating QT to version 5.0.2. Any help would be appreciated.

void gui::on_coordinatesBrowse_clicked()
{
     QString fileName = QFileDialog::getOpenFileName(this,"Open File");
//.....
}

and I have:

gui::gui(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::gui)
{
    ui->setupUi(this);
//.....
}

and

int main(int argc, char *argv[]) 
{
    QApplication a(argc, argv);
    gui mainW;
    mainW.show();
    return a.exec();
}

1条回答
对你真心纯属浪费
2楼-- · 2019-02-26 02:10

I thought i am also experiencing this on Qt5.4.0 x64 on Linux.

I created a similar situation with QtCreator and used the "go to slot..." context menu in widget edit mode (F3) which created a slot automatically for me.

Then i renamed the buttons and renamed the functions and used the slot edit mode (F3) in the .ui file. Since only the connection via the slot edit mode shows up, i thought i was all set. But the old connection was still existing, resulting in two signals...

查看更多
登录 后发表回答