Dear Forumers, I tryed to get input file name by QInputDialog::getText(0 method and came up with strange behaviour. If after click on OK at the dialog window program didn't returned . I made another click and after that I got what I expected after first click. Why ? In case I clicked on Cancel button - everything is Ok. Could you please to give me hint how to get right behaviour ? Se my code below (I am workin on LINUX Debian Wheezy machine). Thank you in advance for help.
Qt Code:
  1. #include <QApplication>
  2. #include <QInputDialog>
  3. #include <QDebug>
  4.  
  5. void writ_file();
  6. QString InputFileName();
  7.  
  8. QString file_name = "test.txt";
  9.  
  10. int main(int argc, char **argv){
  11. QApplication app(argc, argv);
  12. writ_file();
  13. return app.exec();
  14. }
  15.  
  16. void writ_file() {
  17.  
  18. if(InputFileName() == "" ) {
  19. qDebug() << "Input file name -> cancelled. Uses the default name : "
  20. << file_name << endl;
  21. }
  22. else file_name = InputFileName();
  23. qDebug() << "writ_file() -> " << file_name;
  24. return;
  25. }
  26.  
  27. QString InputFileName() {
  28.  
  29. bool bOk;
  30. QString FileName = QInputDialog::getText(0,
  31. "Input File Name",
  32. "Name:",
  33. QLineEdit::Normal,
  34. "test.txt",
  35. &bOk
  36. );
  37. if (!bOk) {
  38. // Была нажата кнопка Cancel
  39. return "";
  40. }
  41. qDebug() << FileName ;
  42. //printed Filename after first click (hanging, don't make return)
  43. // and after second click print again and make return
  44. return FileName;
  45. }
  46. // Output if I press OK
  47. // "test.txt"
  48. // "test.txt"
  49. // writ_file() -> "test.txt"
  50. // Output if I press Cancel
  51. // Input file name -> cancelled. Uses the default name : "test.txt"
  52.  
  53. // writ_file() -> "test.txt"
To copy to clipboard, switch view to plain text mode