I've changed the code in the way you instructed, i get same segmentation fault.
I've changed the code in the way you instructed, i get same segmentation fault.
Qt 5.3 Opensource & Creator 3.1.2
Then you must have a NULL pointer somewhere. What about m_pDatabase? Are you sure it is always valid?
Well, I've checked with gdb, none of actors pointer have NULL or 0 value, according to gdb. What the heck is going on??
Qt 5.3 Opensource & Creator 3.1.2
Could you post the backtrace?
Well, my friends, here is a backtrace:
Qt Code:
(gdb) run Starting program: /home/markofr/working_copy/qKobilica/bin/qkobilica [Thread debugging using libthread_db enabled] [New Thread 47848586376464 (LWP 9931)] Qt: gdb: -nograb added to command-line options. Use the -dograb option to enforce grabbing. Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 47848586376464 (LWP 9931)] 0x0000000000000000 in ?? () (gdb) bt #0 0x0000000000000000 in ?? () #1 0x00002b8496d9e4e3 in QSqlDatabase::record () from /usr/lib/libQtSql.so.4 #2 0x00000000004072c8 in CBrowserWindow (this=0x6cff50, parent=0x663e70, pDataBase=0x66f220, sTableName=@0x7fff13f42830) at cbrowserwindow.cpp:17 #3 0x0000000000405b48 in qKobilica::browseSifrantKrajev (this=0x663e70) at qkobilica.cpp:91 #4 0x0000000000408a5d in qKobilica::qt_metacall (this=0x663e70, _c=QMetaObject::InvokeMetaMethod, _id=0, _a=0x7fff13f42e00) at moc_qkobilica.cpp:66 #5 0x00002b8497c2f770 in QMetaObject::activate () from /usr/lib/libQtCore.so.4 #6 0x00002b8497c2f969 in QMetaObject::activate () from /usr/lib/libQtCore.so.4 #7 0x00002b849718d9ab in QAction::triggered () from /usr/lib/libQtGui.so.4 #8 0x00002b849718f4b8 in QAction::activate () from /usr/lib/libQtGui.so.4 #9 0x00002b849754fea9 in ?? () from /usr/lib/libQtGui.so.4 #10 0x00002b849755264a in QMenu::mouseReleaseEvent () from /usr/lib/libQtGui.so.4 #11 0x00002b84971e15d9 in QWidget::event () from /usr/lib/libQtGui.so.4 #12 0x00002b849754de85 in QMenu::event () from /usr/lib/libQtGui.so.4 #13 0x00002b8497194d51 in QApplicationPrivate::notify_helper () from /usr/lib/libQtGui.so.4 #14 0x00002b8497195949 in QApplication::notify () from /usr/lib/libQtGui.so.4 #15 0x00002b8497c1e846 in QCoreApplication::notifyInternal () from /usr/lib/libQtCore.so.4 #16 0x00002b849719fe73 in ?? () from /usr/lib/libQtGui.so.4 #17 0x00002b84971fa37c in ?? () from /usr/lib/libQtGui.so.4 #18 0x00002b84971f8239 in QApplication::x11ProcessEvent () from /usr/lib/libQtGui.so.4 #19 0x00002b8497226599 in ?? () from /usr/lib/libQtGui.so.4 #20 0x00002b8499f8ffd3 in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0 #21 0x00002b8499f932dd in ?? () from /usr/lib/libglib-2.0.so.0 #22 0x00002b8499f9380e in g_main_context_iteration () from /usr/lib/libglib-2.0.so.0 #23 0x00002b8497c45f4e in QEventDispatcherGlib::processEvents () from /usr/lib/libQtCore.so.4 #24 0x00002b8497225e07 in ?? () from /usr/lib/libQtGui.so.4 #25 0x00002b8497c1bb31 in QEventLoop::processEvents () from /usr/lib/libQtCore.so.4 #26 0x00002b8497c1bc86 in QEventLoop::exec () from /usr/lib/libQtCore.so.4 #27 0x00002b8497c1effc in QCoreApplication::exec () from /usr/lib/libQtCore.so.4 #28 0x00002b8497194928 in QApplication::exec () from /usr/lib/libQtGui.so.4 #29 0x00000000004062fd in main (argc=1, argv=0x7fff13f44638) at main.cpp:13To copy to clipboard, switch view to plain text mode
Qt 5.3 Opensource & Creator 3.1.2
Are you sure you instantiate the QSqlDatabase? It doesn't look like you do.
Can you post the code where you create it? It might be the fact that QSqlDatabase::addDatabase gives you a local copy and you take its address. The pointer will become invalid by the time you pass it to the constructor.
Why don't you use const refs instead?
Well, this is a code:
Qt Code:
// sets up database - params QString db_user,QString db_pass,QString db_name,QString host,QString type Q_CHECK_PTR(m_pDatabaseConnection);To copy to clipboard, switch view to plain text mode
I am quite sure I will be forced to rewrite the MySQLConection class since it obviously does not work!!!
Qt 5.3 Opensource & Creator 3.1.2
Yes, but I was referring to the internal QSqlDatabase pointer. The one from MySqlConnect.
Ok, just a second. Did you mean this chunk of code:
Qt Code:
//connect to database db.setHostName(host); db.setDatabaseName(db_name); db.setUserName(db_user); db.setPassword(db_pass); //get a pointer to a database connection m_pDatabase = &QSqlDatabase::database(); Q_CHECK_PTR(m_pDatabase); //sql table model == read/write model --> navigate and modify individual sql tables Q_CHECK_PTR(m_pModel); //model->setTable(db_table); //all changes will be cached in the model until either submitAll() or revertAll() is called //populates the model with data from the table, using the specified filter and sort conditions //model->select(); } //QSqlDatabase* MySQLConnect::m_pDatabase=0; /* //this function is called if a refresh button is clicked void MySQLConnect::refresh_everything() { model->select(); } void MySQLConnect::change_mysql() { //submits all pending changes to the mysql database model->submitAll(); } */To copy to clipboard, switch view to plain text mode
Qt 5.3 Opensource & Creator 3.1.2
Rewrite it like this:
Qt Code:
//connect to database m_Database.setHostName(host); m_Database.setDatabaseName(db_name); m_Database.setUserName(db_user); m_Database.setPassword(db_pass); bool openedOK = m_Database.open(); Q_CHECK_PTR(m_pModel); ... }To copy to clipboard, switch view to plain text mode
replace m_pDatabase with m_Database (not a pointer).
Bookmarks