Segmentation fault using sqlite
I know this is a typical error message, but I cannot find a solution in the other post I found on it.
I have the following code:
Code:
{
if(datos == NULL){
qDebug() << "NULL database";
return;
}
if(!datos->isOpen()){
qDebug() << "Failed to open the database";
return;
}
qDebug() << "step 1: " << s;
setWindowTitle(s);
qDebug() << "step 2";
ui->listWidget_estad->clear();
qDebug() << "step 3";
ui->listWidget_nombres->clear();
qDebug() << "step 4";
...
}
I get to "Step 1" before the message error:
Quote:
The inferior stopped because it received a signal from the Operating System.
Signal name : SIGSEGV
Signal meaning : Segmentation fault
If I delete setWindowTitle(s); I get the very same error after Step 2. So I am really confused. Can anybody help me?
The program used to work fine before adding new rows into the database.
Re: Segmentation fault using sqlite
Is the Ligas object you are calling this on a valid one?
Cheers,
_
Re: Segmentation fault using sqlite
I think so, because the program worked well before (adding new rows in the database).
The Ligas object is a MainWindow. This is ligas.h:
Code:
#ifndef LIGAS_H
#define LIGAS_H
#include <QMainWindow>
#include <QtSql>
namespace Ui {
class Ligas;
}
{
Q_OBJECT
public:
explicit Ligas
(QWidget *parent
= 0);
~Ligas();
public slots:
private:
Ui::Ligas *ui;
};
#endif // LIGAS_H
And this is ligas.cpp:
Code:
#include "ligas.h"
#include "mainwindow.h"
#include "ui_ligas.h"
ui(new Ui::Ligas)
{
ui->setupUi(this);
}
Ligas::~Ligas()
{
delete ui;
}
{...}
Re: Segmentation fault using sqlite
Your parameter datos can be both not NULL and not valid. Are you sure you are passing a valid pointer that is still valid when this code uses it?
BTW,it is a little unusual to pass a QSqlDatabase by pointer.
Re: Segmentation fault using sqlite
Quote:
Originally Posted by
ChrisW67
Your parameter datos can be both not NULL and not valid. Are you sure you are passing a valid pointer that is still valid when this code uses it?
I suspect it may be possible that I am passing an invalid pointer. But in that case I do not know why, nor why it used to work fine before.
This is the calling procedure:
Code:
void MainWindow
::on_listWidget_competiciones_doubleClicked(const QModelIndex &index
) {
qDebug() << "doubleclick";
if(!datos.isOpen()){
qDebug() << "Failed to open the database";
return;
}
ligas->SetId(index.data().toString(),&datos);
ligas->show();
ligas->raise();
}
Quote:
Originally Posted by
ChrisW67
BTW,it is a little unusual to pass a QSqlDatabase by pointer.
So, what is the most usual way to do that :confused: ? To define it as a global variable?
Re: Segmentation fault using sqlite [SOLVED]
Quote:
Originally Posted by
anda_skoa
Is the Ligas object you are calling this on a valid one?
Cheers,
_
OK. I found the mistake. I had deleted "ligas = new Ligas" unwillingly. So that was the problem. Ligas was NULL.
I still don't know what is the best way to pass a QSqlDatabase. Isn't a good ideo to do it by pointer?