How am i can handle signal "fileselected" (QFileDialog)?[SOLVED]
-
Hello
I have some problem with QFileDialog@QFileDialog dialog = new QFileDialog(this,"Save Map","",".map");
dialog->setAcceptMode(QFileDialog::AcceptSave);
dialog->show();
connect(dialog, SIGNAL(fileSelected(QString)), this, SLOT(saveMap(QString)));@When I clicked "OK" , signal "fileSelected" is sent twice
-
Hi, are you sure you are not connecting the signal twice? maybe you are calling that code twice in a function and never disconnect the signal so you will always add to the same signal. Just an idea.
You can try printing the "sender()" in the slot, see if its the same source or where it comes from. -
I am sure that i'm not connecting the signal twice)
I printing sender() and i get same address twice) -
Hi LiUn, what version of QT, which OS, and what are you attempting to accomplish?
-
I am using Qt5.2, os - ubuntu
I was trying disconnect from this signal when I getting it first time
@void MainWindow::saveMap(QString name)
{
qDebug()<<"saveMap"<<name<<sender();
disconnect(this,SLOT(saveMap(QString)));
}
@
but this doesn't work -
Hi LiUn, I mean that I assume that you are attempting to save a file using the QFileDialog?
-
yes, I'm attempting to save a file using the QFileDialog
-
Hi LiUn, I'm not sure why you would want use connections for anything in this instance, but I recommend trying the following.
@
QString fileName = QFileDialog::getSaveFileName(this, "Save Maps", QDir::currentPath(), "Map Files (.map);;All Files (.*)");
@Then fileName either holds the fileName entered, or nothing if cancel was pressed.
-
oh, thank you ... I think I can use this code instead my
-
You are welcome, don't forget to mark as [SOLVED] if it fixes your problem.
Chris