PDA

View Full Version : Program crash when a signal is emitted



croscato
22nd November 2008, 14:52
I have the following class definition:


#ifndef QMYSQLTABLE_H
#define QMYSQLTABLE_H

#include <QObject>
#include <QSqlQuery>

class QMysqlConnection;

class QMysqlTable: public QObject, protected QSqlQuery
{
Q_OBJECT

friend class QDataLineEdit;

public:
QMysqlTable(const QString& table, const QMysqlConnection* connection,
QObject* = 0);

bool exec(const QString& query);
bool isValid(void) const;

public slots:
bool first(void);
bool previous(void);
bool next(void);
bool last(void);
bool seek(int index, bool relative = false);

signals:
void firstRecord(void);
void previousRecord(void);
void nextRecord(void);
void lastRecord(void);
void seekRecord(void);

private:
const QMysqlConnection* _connection;

const QString& _table;
};

#endif // QMYSQLTABLE_H


and the implementation part the function next() is:


bool QMysqlTable::next(void)
{
if (_connection->isValid()) {
emit nextRecord();

return QSqlQuery::next();
}

return false;
}


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.

caduel
22nd November 2008, 15:00
i) not init. _connection
ii) crash in connected slot
=> use a debugger to find out

croscato
22nd November 2008, 15:09
Hi caduel

gdb returned this:



Program received signal SIGSEGV, Segmentation fault.
0x00007f2fb6069e19 in QString::toUpper () from /usr/lib/qt-4.4.3/lib/libQtCore.so.4

croscato
22nd November 2008, 15:13
I'm attaching the full source code.

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

Thanks.

wysota
22nd November 2008, 15:45
Is there anything connected to this signal?

wysota
22nd November 2008, 16:01
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.

croscato
22nd November 2008, 22:28
I will see if this class has all that I need. But about the error, any ideas?

Thanks, for you reply!

wysota
22nd November 2008, 23:24
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.