Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Segmentation fault in a call of a window with the message at closing of the editor of the delegate
Forum Updated to NodeBB v4.3 + New Features

Segmentation fault in a call of a window with the message at closing of the editor of the delegate

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 2.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mva555
    wrote on 1 Dec 2011, 13:45 last edited by
    #1

    Hi! I can't fix segmentation fault in a call of a window with the message at closing of the editor of the delegate. This is a code:

    main.cpp:
    @
    #include <QtGui/QApplication>
    #include "dialog.h"
    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    Dialog w;
    w.show();
    return a.exec();
    }
    @

    dialog.h:
    @
    #include <QDialog>
    class Dialog : public QDialog
    {
    Q_OBJECT
    public:
    Dialog(QWidget *parent = 0);
    private slots:
    void execute();
    };
    @

    dialog.cpp:
    @
    #include <QDialog>
    #include <QErrorMessage>
    #include <QVBoxLayout>
    #include <QTableWidget>
    #include <QItemDelegate>
    #include "dialog.h"
    Dialog::Dialog(QWidget parent): QDialog(parent) {
    QTableWidget
    fieldsTable = new QTableWidget(2, 1);
    QVBoxLayout* layout = new QVBoxLayout();
    layout->addWidget(fieldsTable);
    QItemDelegate* itemDelegate = new QItemDelegate();
    connect(itemDelegate, SIGNAL(closeEditor(QWidget*)), this, SLOT(execute()));
    fieldsTable->setItemDelegateForColumn(0, itemDelegate);
    setLayout(layout);
    }
    void Dialog::execute() {
    if (true) // The testing function will be here
    {
    QErrorMessage msgBox;
    msgBox.setWindowTitle(QObject::trUtf8("Error!"));
    msgBox.showMessage(QObject::trUtf8("A error text"));
    msgBox.exec();
    }
    }@

    For some reason after end of editing of cell QTableWidget the window with an error message opens twice, and then the program falls out by mistake of segmentation. If instead of a call of window QErrorMessage to substitute easier message qDebug () <<"the Error!", all works normally. This problem exists only in Linux.
    What is wrong?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      broadpeak
      wrote on 1 Dec 2011, 16:50 last edited by
      #2

      @
      connect(itemDelegate, SIGNAL(closeEditor(QWidget*, ???????)), this, SLOT(execute()));
      @

      ??????? = QAbstractItemDelegate::EndEditHint

      I think, "hint" is a required parameter.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on 1 Dec 2011, 17:01 last edited by
        #3

        It depends on the method you use to get out of the editing cell. Using tab, for example, you can close the editor of the current cell and open the next cell. The close of the first cell triggers your slot, the message box takes way focus and thus triggers the close of the second cell's editor, hence your slot is called twice. Using qDebug() does not trigger this, as there is no popup stealing the focus.

        From a quick look at the docs, I doubt that it is ok to use two QErrorMessage dialogs simultaneously (what you probably do). I would add a member pointing to a pointer to a QErrorMessage dialog in the header, create that in the constructor and reuse that instead of creating a new msgBox every time.

        If that doesn't work, build your app in debug mode and run it through a debugger to get a useful stack trace.

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0

        1/3

        1 Dec 2011, 13:45

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved