PDA

View Full Version : Segmentation error, dock icons doesnt appears, slots not recognized



phapha
29th October 2011, 19:26
Hi all,
I'm writing an application and when th compilation is doing well; But when I launch it I have the following messages from debugger :



Début du débogageObject::connect: No such slot FenetrePrincipale::genPdf(m_userView,filename) in ..\callTracker\PageUser.cpp:52
Object::connect: No such slot FenetrePrincipale::goTab(m_search,titre) in ..\callTracker\FenetrePrincipale.cpp:49
Object::connect: No such slot FenetrePrincipale::goTab(m_user,titre) in ..\callTracker\FenetrePrincipale.cpp:55
Object::connect: No such slot FenetrePrincipale::goTab(m_user,titre) in ..\callTracker\FenetrePrincipale.cpp:61
Object::connect: No such slot FenetrePrincipale::genPdf(m_search,filename) in ..\callTracker\FenetrePrincipale.cpp:67
Object::connect: No such slot FenetrePrincipale::goTab(m_stat,titre) in ..\callTracker\FenetrePrincipale.cpp:73
Object::connect: No such slot FenetrePrincipale::goTab(m_accueil,titre) in ..\callTracker\FenetrePrincipale.cpp:79


In addition, th icons of my dock doesn't appears.
And finally, I got a segmentation error message when I click on search and Make report buttons on the PageAccueil. Can you help me?

FenetrePrincipale.h


#ifndef FENETREPRINCIPALE_H
#define FENETREPRINCIPALE_H

#include <QtGui>
#include <QMainWindow>
#include <QtSql>
#include "sstream"
#include "PageAccueil.h"
#include "PageRecherche.h"
#include "PageStat.h"
#include "PageUser.h"

class FenetrePrincipale : public QMainWindow
{
Q_OBJECT

public:
explicit FenetrePrincipale(QWidget *parent = 0);

private:
void creerAction();
void creerDock();

public slots:
void creerPageRapport();
void genPdf(QWidget *view, QString filename);

void goTab(QWidget *page, QString title);
void goTabint(int position);

private:
QTabWidget *m_onglets;

PageAccueil *m_accueil;
PageRecherche *m_search;
PageStat *m_stat;
PageUser *m_user;

QAction *actionAddUser;
QAction *actionConfig;
QAction *actionSearchCall;
QAction *actionDelUser;
QAction *actionModUser;
QAction *actionReport;
QAction *actionStat;
QAction *actionretourAccueil;
QAction *actionQuit;

};

#endif // FENETREPRINCIPALE_H


FenetrePrincipale.cpp


#include "FenetrePrincipale.h"

FenetrePrincipale::FenetrePrincipale(QWidget *parent) :
QMainWindow(parent)
{
m_accueil=new PageAccueil(this);
m_stat=new PageStat(this);
m_user=new PageUser(this);

creerAction();
creerDock();

m_onglets=new QTabWidget;
m_onglets->setTabPosition(QTabWidget::East);
m_onglets->addTab(m_accueil,tr("Home"));
m_onglets->addTab(m_user,tr("User"));
m_onglets->addTab(m_stat,tr("Statistics"));

connect(m_onglets,SIGNAL(currentChanged(int)),this ,SLOT(goTabint(int)));
setCentralWidget(m_onglets);

m_onglets->setTabsClosable(true);

setMinimumSize(500,350);
setWindowIcon(QIcon("images/logo.png"));
setWindowTitle(tr("callTracker"));
}


void FenetrePrincipale::creerAction()
{
actionAddUser=new QAction(QIcon("images/add.png"),tr("Add a &user"),this);
actionAddUser->setShortcut(tr("Ctrl+U"));
connect(actionAddUser,SIGNAL(triggered()),m_user,S LOT(addBoite()));

actionSearchCall=new QAction(QIcon("images/search.png"),tr("&Search a call"),this);
actionSearchCall->setShortcut(tr("Ctrl+S"));
QString titre("Search & Report");
connect(actionSearchCall,SIGNAL(triggered()),this, SLOT(goTab(m_search,titre)));

actionDelUser=new QAction(QIcon("images/del.png"), tr("&Delete user informations"),this);
actionDelUser->setShortcut(tr("Ctrl+D"));
titre=tr("&User");
connect(actionDelUser,SIGNAL(triggered()),this,SLO T(goTab(m_user,titre)));

actionModUser=new QAction(tr("&Update user informations"),this);
actionModUser->setShortcut(tr("Ctrl+M"));
titre=tr("User");
connect(actionModUser,SIGNAL(triggered()),this,SLO T(goTab(m_user,titre)));

actionReport=new QAction(QIcon("images/rapport"),tr("&Generate a call report"),this);
actionReport->setShortcut(tr("Ctrl+G"));
QString filename=tr("Report");
connect(actionReport,SIGNAL(triggered()),this,SLOT (genPdf(m_search,filename)));

actionStat=new QAction(tr("&View calls statistics"),this);
actionStat->setShortcut(tr("Ctrl+V"));
titre=tr("&Statistics");
connect(actionStat,SIGNAL(triggered()),this,SLOT(g oTab(m_stat,titre)));

actionretourAccueil=new QAction(QIcon("images/accueil.png"),tr("&Home"),this);
actionretourAccueil->setShortcut(tr("Ctrl+A"));
titre=tr("Home");
connect(actionretourAccueil,SIGNAL(triggered()),th is,SLOT(goTab(m_accueil,titre)));

actionQuit=new QAction(QIcon("images/quit.png"),tr("&Quit"),this);
actionQuit->setShortcut(tr("Ctrl+V"));
connect(actionQuit,SIGNAL(triggered()),qApp,SLOT(q uit()));

}


void FenetrePrincipale::creerDock()
{
QDockWidget *dock=new QDockWidget(tr("Actions"),this);
addDockWidget(Qt::LeftDockWidgetArea,dock);
dock->setFeatures(QDockWidget::NoDockWidgetFeatures);
dock->setFixedWidth(100);

QWidget *contenuDock=new QWidget;
dock->setWidget(contenuDock);

QToolButton *add = new QToolButton;
QToolButton *search = new QToolButton;
QToolButton *del = new QToolButton;
QToolButton *mod=new QToolButton;
QToolButton *report = new QToolButton;
QToolButton *retAcc = new QToolButton;
QToolButton *stati=new QToolButton;
QToolButton *quit=new QToolButton;

add->setIcon(QIcon("images/add.png"));
search->setIcon(QIcon("images/search.png"));
del->setIcon(QIcon("images/del.png"));
mod->setIcon(QIcon("images/mod.png"));
report->setIcon(QIcon("images/report.png"));
retAcc->setIcon(QIcon("images/home.png"));
stati->setIcon(QIcon("images/stat.png"));
quit->setIcon(QIcon("images/quit.png"));

add->addAction(actionAddUser);
search->addAction(actionSearchCall);
del->addAction(actionDelUser);
mod->addAction(actionModUser);
report->addAction(actionReport);
retAcc->addAction(actionretourAccueil);
stati->addAction(actionStat);
quit->addAction(actionQuit);


QVBoxLayout *dockLayout=new QVBoxLayout;
dockLayout->addWidget(add);
dockLayout->addWidget(search);
dockLayout->addWidget(del);
dockLayout->addWidget(mod);
dockLayout->addWidget(report);
dockLayout->addWidget(retAcc);
dockLayout->addWidget(stati);
dockLayout->addWidget(quit);

contenuDock->setLayout(dockLayout);

}

void FenetrePrincipale::goTab(QWidget *page,QString title)
{
int position=m_onglets->indexOf(page);
if(position==-1)
{
m_onglets->addTab(page,title);
}
else
{
m_onglets->setCurrentWidget(page);
};
}

void FenetrePrincipale::goTabint(int position)
{
if(position!=-1)
{
m_onglets->setCurrentIndex(position);
};
}

void FenetrePrincipale::creerPageRapport()
{
goTab(m_search,tr("Search & Report"));
}

void FenetrePrincipale::genPdf(QWidget *view, QString filename)
{
QPrinter printer(QPrinter::HighResolution);
printer.setOutputFileName(filename);
printer.setPaperSize(QPrinter::A4);
printer.setOutputFormat(QPrinter::PdfFormat);
}


PageAccueil.cpp


#include "PageAccueil.h"

void PageAccueil::initializeModel(QSqlRelationalTableMo del *model)
{
model->setTable("callId");

model->setEditStrategy(QSqlTableModel::OnManualSubmit);
model->setRelation(8, QSqlRelation("destination", "number", "type"));
model->setRelation(9, QSqlRelation("user", "cos", "name"));
model->setRelation(10, QSqlRelation("user", "cos","firstname"));

model->setHeaderData(0, Qt::Horizontal, tr("Nbr"));
model->setHeaderData(7, Qt::Horizontal, tr("Caller extension"));
model->setHeaderData(1, Qt::Horizontal, tr("Date"));
model->setHeaderData(2, Qt::Horizontal, tr("Hour"));
model->setHeaderData(3, Qt::Horizontal, tr("Duration"));
model->setHeaderData(4, Qt::Horizontal, tr("transfert"));
model->setHeaderData(5, Qt::Horizontal, tr("transfered call?"));
model->setHeaderData(6, Qt::Horizontal, tr("cos used?"));
model->setHeaderData(12, Qt::Horizontal, tr("Destination type"));
model->setHeaderData(11, Qt::Horizontal, tr("Last Name"));
model->setHeaderData(10, Qt::Horizontal, tr("First Name"));

model->select();
}

QTableView *PageAccueil::createView(const QString &title, QSqlTableModel *model)
{
QTableView *view = new QTableView;
view->setModel(model);
view->setItemDelegate(new QSqlRelationalDelegate(view));
view->setWindowTitle(title);
return view;
}

PageAccueil::PageAccueil(QWidget *parent) :
QWidget(parent)
{
QSqlRelationalTableModel model;
initializeModel(&model);

QTableView *view = createView(QObject::tr("Lasts calls"), &model);

view->setEditTriggers(QAbstractItemView::NoEditTriggers) ;

QPushButton *searchBut=new QPushButton(tr("Search"));
QPushButton *reportBut=new QPushButton(tr("Make a report"));

QVBoxLayout *layoutPage=new QVBoxLayout(this);
layoutPage->addWidget(view);
layoutPage->addWidget(searchBut);
layoutPage->addWidget(reportBut);

setLayout(layoutPage);

connect(searchBut,SIGNAL(clicked()),parent,SLOT(cr eerPageRapport()));
connect(reportBut,SIGNAL(clicked()),parent,SLOT(cr eerPageRapport()));
}


Many thanks.

I forgot the PageAccueil.h


#ifndef PAGEACCUEIL_H
#define PAGEACCUEIL_H

#include <QtGui>
#include <QtSql>


class PageAccueil : public QWidget
{
Q_OBJECT
public:
explicit PageAccueil(QWidget *parent = 0);

private:
void initializeModel(QSqlRelationalTableModel *model);
QTableView *createView(const QString &title, QSqlTableModel *model);

};

#endif // PAGEACCUEIL_H

franz
29th October 2011, 21:49
Début du débogageObject::connect: No such slot FenetrePrincipale::genPdf(m_userView,filename) in ..\callTracker\PageUser.cpp:52
Object::connect: No such slot FenetrePrincipale::goTab(m_search,titre) in ..\callTracker\FenetrePrincipale.cpp:49
...


You have to connect signals and slots using their signature, not variables.

connect(mySender, SIGNAL(mySignal(int,int)), myReceiver, SLOT(mySlot(int,int)));
You do this correctly more than a few times.
This won't work:

connect(actionModUser,SIGNAL(triggered()),this,SLO T(goTab(m_user,titre)));

What you might need to do here, is create a slot that takes no arguments:


connect(actionModUser, SIGNAL(triggered()), this, SLOT(onActionModUserTriggered()));

// ...
void FenetrePrincipale::onActionModUserTriggered()
{
// ...
goTab(m_user, titre);
}


I couldn't look into the dock widget.

Then the segfault:



PageAccueil::PageAccueil(QWidget *parent) :
QWidget(parent)
{
QSqlRelationalTableModel model;


model is local to this function. You pass it to other objects that keep a pointer to it, but it will be destroyed at the end of this function (the ampersand is a red flag in these cases). Fix it by creating it on the heap:



PageAccueil::PageAccueil(QWidget *parent) :
QWidget(parent)
{
QSqlRelationalTableModel *model = new QSqlRelationalTableModel(this);
initializeModel(model);

QTableView *view = createView(QObject::tr("Lasts calls"), model);
// ...
}

phapha
30th October 2011, 13:34
Thank you Franz; It works. But I have another problem; I m trying to create 3tables in my SQlite database. I use the following code.


QSqlQuery query;
query.exec("create table user (UPI int primary key, firstname varchar, lastname varchar, cos int )");
query.exec("insert into person values(380142, 'Danny', 'Young',10)");
query.exec("insert into person values(102222, 'Christine', 'Holand',23)");

//The following requests create the tables, but don't insert the data
query.exec("create table destination (number int primary key,type varchar)");
query.exec("insert into destination values(0022921301074, 'local')");
query.exec("insert into destination values(002217780216, 'international')");

//The requests below gives an error message
query.exec("create table callId (id int primary key, ext int)")/*, day varchar, moment varchar,duree int,transfer int, transferExist bool,cosExist bool, number int, cos int)")*/;
query.exec("insert into callId values(' ', '2011-10-28','17:25',128,3300,'true','false',0022921301074, ' ')");
query.exec("insert into callId values(' ', '2011-10-29','00:29',128,' ','false','true',002217780216,10)");


The error message is "This application has request the Runtime to terminate at an unusual way".

And the debugger show the following message :
Début du débogageASSERT: "idx >= 0 && idx < s" in file ..\..\include/QtCore/../../../../../../ndk_buildrepos/qt-desktop/src/corelib/tools/qvarlengtharray.h, line 107
Invalid parameter passed to C runtime function.
Invalid parameter passed to C runtime function.
Fin du débogage

Kindly help me;
Thanks