Results 1 to 8 of 8

Thread: Program crash when a signal is emitted

  1. #1
    Join Date
    Oct 2008
    Location
    Brasil - São Paulo - Marília
    Posts
    28
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    3

    Default Program crash when a signal is emitted

    I have the following class definition:
    Qt Code:
    1. #ifndef QMYSQLTABLE_H
    2. #define QMYSQLTABLE_H
    3.  
    4. #include <QObject>
    5. #include <QSqlQuery>
    6.  
    7. class QMysqlConnection;
    8.  
    9. class QMysqlTable: public QObject, protected QSqlQuery
    10. {
    11. Q_OBJECT
    12.  
    13. friend class QDataLineEdit;
    14.  
    15. public:
    16. QMysqlTable(const QString& table, const QMysqlConnection* connection,
    17. QObject* = 0);
    18.  
    19. bool exec(const QString& query);
    20. bool isValid(void) const;
    21.  
    22. public slots:
    23. bool first(void);
    24. bool previous(void);
    25. bool next(void);
    26. bool last(void);
    27. bool seek(int index, bool relative = false);
    28.  
    29. signals:
    30. void firstRecord(void);
    31. void previousRecord(void);
    32. void nextRecord(void);
    33. void lastRecord(void);
    34. void seekRecord(void);
    35.  
    36. private:
    37. const QMysqlConnection* _connection;
    38.  
    39. const QString& _table;
    40. };
    41.  
    42. #endif // QMYSQLTABLE_H
    To copy to clipboard, switch view to plain text mode 

    and the implementation part the function next() is:
    Qt Code:
    1. bool QMysqlTable::next(void)
    2. {
    3. if (_connection->isValid()) {
    4. emit nextRecord();
    5.  
    6. return QSqlQuery::next();
    7. }
    8.  
    9. return false;
    10. }
    To copy to clipboard, switch view to plain text mode 

    the code for the next() function only work if the nextRecord() signal is not emited. Otherwise the program crashes.

    What could have been causing this behavior?

    Thanks in advance.
    Last edited by croscato; 22nd November 2008 at 13:57.

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Program crash when a signal is emitted

    i) not init. _connection
    ii) crash in connected slot
    => use a debugger to find out

  3. #3
    Join Date
    Oct 2008
    Location
    Brasil - São Paulo - Marília
    Posts
    28
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    3

    Default Re: Program crash when a signal is emitted

    Hi caduel

    gdb returned this:

    Qt Code:
    1. Program received signal SIGSEGV, Segmentation fault.
    2. 0x00007f2fb6069e19 in QString::toUpper () from /usr/lib/qt-4.4.3/lib/libQtCore.so.4
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Oct 2008
    Location
    Brasil - São Paulo - Marília
    Posts
    28
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    3

    Default Re: Program crash when a signal is emitted

    I'm attaching the full source code.

    Caduel if you have a free time, please have a look in it.

    Thanks.
    Attached Files Attached Files

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Program crash when a signal is emitted

    Is there anything connected to this signal?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Program crash when a signal is emitted

    I just had a brief look at your code. Have you seen a class called QDataWidgetMapper? I think you are trying to do something which is already in Qt.

  7. #7
    Join Date
    Oct 2008
    Location
    Brasil - São Paulo - Marília
    Posts
    28
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    3

    Default Re: Program crash when a signal is emitted

    I will see if this class has all that I need. But about the error, any ideas?

    Thanks, for you reply!

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Program crash when a signal is emitted

    I don't have MySQL installed, so I can't test it. Anyway, you should really do some reading. Instead of your custom classes you should use QSqlTableModel and QDataWidgetMapper. All your wrappers are completely redundant.

    By the way, naming files using mixed case names is a really bad habit, try to avoid it.

    Here is some code for you to play with... Oh... try changing the values in the field - they actaully get stored in the database.
    Attached Files Attached Files

Similar Threads

  1. Replies: 5
    Last Post: 27th April 2009, 23:29
  2. Replies: 2
    Last Post: 16th August 2007, 00:20
  3. creating treeWidgetItem using emitted signal from thread class
    By santosh.kumar in forum Qt Programming
    Replies: 1
    Last Post: 25th June 2007, 08:37
  4. Replies: 5
    Last Post: 9th March 2007, 12:51
  5. QT MySQL
    By sabeeshcs in forum Newbie
    Replies: 6
    Last Post: 12th January 2007, 04:19

Tags for this Thread

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.