Results 1 to 10 of 10

Thread: QFileDialog failed by ueing Keyboard

  1. #1
    Join Date
    Feb 2016
    Posts
    21
    Qt products
    Qt5
    Platforms
    Unix/X11

    Exclamation QFileDialog failed by ueing Keyboard

    Hi

    I'm using QT5 from Ubuntu 16.04 and have troubles when i use the keyboard.
    Qt Version 5.5.1.

    When i select all Buttons or Files with the Mouse it works fine, but when i to the work with the Keyboard and press Enter i got a SIGSEGV
    by using getSaveFileName. getExistingDirectory works fine.


    The inferior stopped because it received a signal from the operating system.
    Signal name : SIGSEGV
    Signal meaning : Segmentation fault

    Qt Code:
    1. void ExportDialog::onExportButton_clicked()
    2. {
    3. QSettings settings(QSettings::IniFormat, QSettings::UserScope, "XX", "XX");
    4. QString lastUsedDirectory = settings.value("lastUsedDirectory", QDir::currentPath()).toString();
    5.  
    6. if (m_saveTodir) {
    7. m_filename = QFileDialog::getExistingDirectory(this, tr("Save to ..."),lastUsedDirectory);
    8. } else {
    9. m_filename = QFileDialog::getSaveFileName(this, tr("save"), lastUsedDirectory, "CSV (*.csv)");
    10. }
    11.  
    12. if (m_filename.isNull())
    13. return;
    14.  
    15. settings.setValue("lastUsedDirectory", m_filename);
    16.  
    17. QDialog::accept();
    18.  
    19. }
    To copy to clipboard, switch view to plain text mode 

    Can you tell me what i'm doing wrong?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QFileDialog failed by ueing Keyboard

    Your code looks fine.
    Did you have a look at the stack trace of the crash?

    Is your application showing the Qt file dialog or a native one?

    Cheers,
    _

  3. #3
    Join Date
    Feb 2016
    Posts
    21
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: QFileDialog failed by ueing Keyboard

    It's in both case's Native and not Native.

    But i see after new Debug and rewrite the code some times the crash comes after the QDialog::accept()

    It's not the QFileDialog, it's a QMessageBox after the QDialog::accept() in parent Class. Sorry

    I do not see why, but when i do a delete ExportDialog before i call the QMessageBox it seems to work.

    Workflow

    new ExportDialog
    if (ExportDialog ....)
    QMessageBox will send the SIG

    But

    new ExportDialog
    if (ExportDialog ....)
    delete ExportDialog;
    QMessageBox will work.


    Strong but why it work when i walk through the FileDialog with Mouseclicks.

    So the Error is not QFileDialog alone. It's only when i use in parent class a QMessagebox before i delete the Dialog.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QFileDialog failed by ueing Keyboard

    Very strange.

    Can you provide a compilable minimal example that shows that behavior?

    Cheers,
    _

  5. #5
    Join Date
    Feb 2016
    Posts
    21
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: QFileDialog failed by ueing Keyboard

    Yes i can ;-)

    You can select all with mouse, you must not use the keyboard.
    But When you press Enter on your Keyboard to save the file and not click with Mouse on "Save" Button it crashes
    When you click with Mouse the "Save" Button int works.

    .pro
    Qt Code:
    1. #-------------------------------------------------
    2. #
    3. # Project created by QtCreator 2016-12-05T11:36:37
    4. #
    5. #-------------------------------------------------
    6.  
    7. QT += core gui
    8.  
    9. greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    10.  
    11. TARGET = dialogtest
    12. TEMPLATE = app
    13.  
    14.  
    15. SOURCES += main.cpp\
    16. exportdialog.cpp
    17.  
    18. HEADERS += exportdialog.h
    19.  
    20. FORMS += exportdialog.ui
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include "exportdialog.h"
    2. #include <QApplication>
    3. #include <QMessageBox>
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication a(argc, argv);
    8. ExportDialog *dlg = new ExportDialog(false);
    9. if (dlg->exec() == QDialog::Accepted ) {
    10. QString filename = dlg->getFilename();
    11. if (true /* doExport(filename, dlg->getFrom(), dlg->getTo()) */) {
    12. QMessageBox::information(0, "Export", QString("saved to %1").arg(filename));
    13. } else {
    14. QMessageBox::warning(0, "Export", QString("Can't save to %1").arg(filename));
    15. }
    16. }
    17. delete dlg;
    18.  
    19.  
    20. return a.exec();
    21. }
    To copy to clipboard, switch view to plain text mode 

    exportdialog.cpp
    Qt Code:
    1. #include "exportdialog.h"
    2. #include <QFileDialog>
    3.  
    4. #include "ui_exportdialog.h"
    5.  
    6. ExportDialog::ExportDialog( bool save2dir, QWidget *parent)
    7. : QDialog(parent), ui(new Ui::ExportDialog), m_saveTodir(save2dir)
    8. {
    9. ui->setupUi(this);
    10.  
    11. m_fromDT = new QDateTime;
    12. m_toDT = new QDateTime;
    13. m_filename = "";
    14.  
    15. QString sDate = QString("%1-01-01").arg(QDate::currentDate().year());
    16. QDate date = QDate::fromString(sDate,"yyyy-MM-dd");
    17.  
    18. ui->dateEditTo->setDate(QDate::currentDate());
    19. ui->dateEditFrom->setDate(date);
    20.  
    21. m_fromDT->setDate(date);
    22. m_toDT->setDate(QDate::currentDate());
    23. m_toDT->setTime(QTime::fromString("23:59:59"));
    24.  
    25. connect(ui->cancelButton, SIGNAL(clicked()), this, SLOT(onCancelButton_clicked()));
    26. connect(ui->exportButton, SIGNAL(clicked()), this, SLOT(onExportButton_clicked()));
    27.  
    28. connect(ui->dateEditFrom, SIGNAL(dateChanged(QDate)), this, SLOT(onDateEditFrom_dateChanged(QDate)));
    29. connect(ui->dateEditTo, SIGNAL(dateChanged(QDate)), this, SLOT(onDateEditTo_dateChanged(QDate)));
    30.  
    31. }
    32.  
    33. ExportDialog::~ExportDialog()
    34. {
    35. delete ui;
    36. delete m_fromDT;
    37. delete m_toDT;
    38. }
    39.  
    40. QString ExportDialog::getFilename()
    41. {
    42. return m_filename;
    43. }
    44.  
    45. QString ExportDialog::getFrom()
    46. {
    47. return m_fromDT->toString(Qt::ISODate);
    48. }
    49.  
    50. QString ExportDialog::getTo()
    51. {
    52. return m_toDT->toString(Qt::ISODate);
    53. }
    54.  
    55. void ExportDialog::onCancelButton_clicked()
    56. {
    57. this->close();
    58. }
    59.  
    60. void ExportDialog::onDateEditTo_dateChanged(const QDate &date)
    61. {
    62. m_toDT->setDate(date);
    63. m_toDT->setTime(QTime::fromString("23:59:59"));
    64. }
    65.  
    66. void ExportDialog::onDateEditFrom_dateChanged(const QDate &date)
    67. {
    68. m_fromDT->setDate(date);
    69. }
    70.  
    71. void ExportDialog::onExportButton_clicked()
    72. {
    73. if (m_saveTodir) {
    74. m_filename = QFileDialog::getExistingDirectory(this, "Save to ...");
    75. } else {
    76. m_filename = QFileDialog::getSaveFileName(this, "save", "", "Journal (*.csv)");
    77. }
    78.  
    79. if (m_filename.isNull())
    80. return;
    81.  
    82. QDialog::accept();
    83.  
    84. }
    To copy to clipboard, switch view to plain text mode 

    eportdialog.h
    Qt Code:
    1. #ifndef EXPORTDIALOG_H
    2. #define EXPORTDIALOG_H
    3.  
    4. #include <QDialog>
    5.  
    6. namespace Ui {
    7. class ExportDialog;
    8. }
    9.  
    10. class ExportDialog : public QDialog
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. ExportDialog(bool save2dir, QWidget *parent = 0);
    16. ~ExportDialog();
    17. QString getFilename();
    18. QString getFrom();
    19. QString getTo();
    20.  
    21. private slots:
    22. void onCancelButton_clicked();
    23. void onDateEditTo_dateChanged(const QDate &date);
    24. void onDateEditFrom_dateChanged(const QDate &date);
    25. void onExportButton_clicked();
    26.  
    27. private:
    28. Ui::ExportDialog *ui;
    29.  
    30. bool m_saveTodir;
    31. QDateTime *m_fromDT;
    32. QDateTime *m_toDT;
    33. QString m_filename;
    34.  
    35. };
    36.  
    37. #endif // EXPORTDIALOG_H
    To copy to clipboard, switch view to plain text mode 

    exportdialog.ui
    Qt Code:
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <ui version="4.0">
    3. <class>ExportDialog</class>
    4. <widget class="QDialog" name="ExportDialog">
    5. <property name="geometry">
    6. <rect>
    7. <x>0</x>
    8. <y>0</y>
    9. <width>340</width>
    10. <height>191</height>
    11. </rect>
    12. </property>
    13. <property name="windowTitle">
    14. <string>Dialog</string>
    15. </property>
    16. <layout class="QHBoxLayout" name="horizontalLayout_3">
    17. <item>
    18. <layout class="QVBoxLayout" name="verticalLayout">
    19. <item>
    20. <widget class="QLabel" name="exportLabel">
    21. <property name="font">
    22. <font>
    23. <family>Arial</family>
    24. <pointsize>12</pointsize>
    25. <weight>75</weight>
    26. <bold>true</bold>
    27. </font>
    28. </property>
    29. <property name="text">
    30. <string>Exportieren</string>
    31. </property>
    32. <property name="alignment">
    33. <set>Qt::AlignCenter</set>
    34. </property>
    35. </widget>
    36. </item>
    37. <item>
    38. <layout class="QHBoxLayout" name="horizontalLayout">
    39. <item>
    40. <widget class="QDateEdit" name="dateEditFrom">
    41. <property name="accessibleName">
    42. <string notr="true"/>
    43. </property>
    44. <property name="accessibleDescription">
    45. <string notr="true"/>
    46. </property>
    47. <property name="currentSection">
    48. <enum>QDateTimeEdit::DaySection</enum>
    49. </property>
    50. <property name="calendarPopup">
    51. <bool>true</bool>
    52. </property>
    53. </widget>
    54. </item>
    55. <item>
    56. <widget class="QLabel" name="label">
    57. <property name="text">
    58. <string>-</string>
    59. </property>
    60. <property name="alignment">
    61. <set>Qt::AlignCenter</set>
    62. </property>
    63. </widget>
    64. </item>
    65. <item>
    66. <widget class="QDateEdit" name="dateEditTo">
    67. <property name="accessibleName">
    68. <string notr="true"/>
    69. </property>
    70. <property name="accessibleDescription">
    71. <string notr="true"/>
    72. </property>
    73. <property name="calendarPopup">
    74. <bool>true</bool>
    75. </property>
    76. </widget>
    77. </item>
    78. </layout>
    79. </item>
    80. <item>
    81. <spacer name="verticalSpacer">
    82. <property name="orientation">
    83. <enum>Qt::Vertical</enum>
    84. </property>
    85. <property name="sizeHint" stdset="0">
    86. <size>
    87. <width>20</width>
    88. <height>40</height>
    89. </size>
    90. </property>
    91. </spacer>
    92. </item>
    93. <item>
    94. <layout class="QHBoxLayout" name="horizontalLayout_2">
    95. <item>
    96. <widget class="QPushButton" name="exportButton">
    97. <property name="minimumSize">
    98. <size>
    99. <width>150</width>
    100. <height>60</height>
    101. </size>
    102. </property>
    103. <property name="text">
    104. <string>Export</string>
    105. </property>
    106. </widget>
    107. </item>
    108. <item>
    109. <widget class="QPushButton" name="cancelButton">
    110. <property name="minimumSize">
    111. <size>
    112. <width>150</width>
    113. <height>60</height>
    114. </size>
    115. </property>
    116. <property name="sizeIncrement">
    117. <size>
    118. <width>0</width>
    119. <height>0</height>
    120. </size>
    121. </property>
    122. <property name="text">
    123. <string>Cancel</string>
    124. </property>
    125. <property name="iconSize">
    126. <size>
    127. <width>32</width>
    128. <height>32</height>
    129. </size>
    130. </property>
    131. </widget>
    132. </item>
    133. </layout>
    134. </item>
    135. </layout>
    136. </item>
    137. </layout>
    138. </widget>
    139. <resources/>
    140. <connections/>
    141. </ui>
    To copy to clipboard, switch view to plain text mode 

    lg Chris


    Added after 4 minutes:


    When i do this ...

    main.cpp
    Qt Code:
    1. #include "exportdialog.h"
    2. #include <QApplication>
    3. #include <QMessageBox>
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication a(argc, argv);
    8. ExportDialog *dlg = new ExportDialog(false);
    9. if (dlg->exec() == QDialog::Accepted ) {
    10. QString filename = dlg->getFilename();
    11. if (true /* doExport(filename, dlg->getFrom(), dlg->getTo()) */) {
    12. delete dlg;
    13. QMessageBox::information(0, "Export", QString("saved to %1").arg(filename));
    14. } else {
    15. delete dlg;
    16. QMessageBox::warning(0, "Export", QString("Can't save to %1").arg(filename));
    17. }
    18. }
    19.  
    20. return a.exec();
    21. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by ckvsoft; 5th December 2016 at 12:14.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QFileDialog failed by ueing Keyboard

    Cooll, thanks.

    But maybe you could make a ZIP file with all that content and attach that?

    Cheers,
    _

  7. #7
    Join Date
    Feb 2016
    Posts
    21
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: QFileDialog failed by ueing Keyboard

    Sorry here it is ...

    New knowledge
    It works on 64 Bit but not on 32 Bit

    lg Chris
    Attached Files Attached Files

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QFileDialog failed by ueing Keyboard

    Hmm, it works for me but I am also on a 64 bit system, don't have any 32 bit system anymore.

    Have you tried if it works then the actual event loop is also running? I.e. when the dialog is called from somewhere after app.exec() has started?

    A couple of observations:

    * Your "this works" section will also crash, you are deleting dlg and the you are accessing it
    * You don't need to application QDateTime on the heap, just normal members will do
    * You could connect the cancel button directly to the "close()" slot, even better would be to connect it to the "reject()" slot.

    Cheers,
    _

  9. #9
    Join Date
    Feb 2016
    Posts
    21
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: QFileDialog failed by ueing Keyboard

    Thx

    Upps. But I only access dlg in this example. My be I don't see this. In my real code it's ok.

    In my real application it's used after application exec

    How I should use qdatetime in my case?
    LG chris

  10. #10
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QFileDialog failed by ueing Keyboard

    Quote Originally Posted by ckvsoft View Post
    Upps. But I only access dlg in this example. My be I don't see this. In my real code it's ok.
    Ok. In the attached code you are accessing "dlg" after its delete.

    Quote Originally Posted by ckvsoft View Post
    How I should use qdatetime in my case?
    Just a non-pointer members.

    Cheers,
    _

Similar Threads

  1. APK Build Failed
    By Mathan in forum Qt Programming
    Replies: 0
    Last Post: 1st August 2016, 13:39
  2. failed to crosscompiling with qt 4.8
    By bkroy in forum Qt Programming
    Replies: 1
    Last Post: 5th January 2016, 23:56
  3. Build failed
    By anh5kor in forum Newbie
    Replies: 1
    Last Post: 25th March 2015, 15:33
  4. How to implement visual keyboard in a QFileDialog
    By johnson604 in forum Qt Programming
    Replies: 2
    Last Post: 22nd November 2014, 21:22
  5. Replies: 7
    Last Post: 5th March 2014, 18:36

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.