Aniket Awati
Aniket Awati

Reputation: 1421

QMessageBox segFaulting in Mainwindows slot onlclick

In my qt mobile app I have a list. I have connected list clicked to a slot of main window.

connect(view,SIGNAL(clicked(QModelIndex)),this,SLOT(showMessage()));

void MainWindow::showMessage()
{
    QMessageBox::information(this,"info","info",QMessageBox::Ok,0);
}

Now if i put 'QMessageBox::information(this,"info","info",QMessageBox::Ok,0);' in constructor it works.

else it gives segmentation fault.

0 QWidgetPrivate::setParent_sys qwidget_simulator.cpp 207 0x0083195e
1 QWidget::setParent qwidget.cpp 9985 0x00820784
2 QWidget::setParent qwidget.cpp 9942 0x00820508
3 QFocusFramePrivate::update qfocusframe.cpp 72 0x00c337d1
4 QFocusFrame::setWidget qfocusframe.cpp 231 0x00c340aa
5 QS60Style::event qs60style.cpp 3277 0x00b569e2
6 QApplicationPrivate::notify_helper qapplication.cpp 4415 0x007d84b6
7 QApplication::notify qapplication.cpp 3817 0x007d5f0f
8 QCoreApplication::notifyInternal qcoreapplication.cpp 732 0x6a1fe5bc
9 QCoreApplication::sendEvent qcoreapplication.h 215 0x00e3ac02
10 QApplicationPrivate::setFocusWidget qapplication.cpp 2210 0x007d316c
11 QWidget::setFocus qwidget.cpp 6288 0x00819c21
12 QApplication::setActiveWindow qapplication.cpp 2590 0x007d3df8
13 QWidget::activateWindow qwidget_simulator.cpp 601 0x00832c02
14 QWidgetPrivate::show_sys qwidget_simulator.cpp 242 0x00831af4
15 QWidgetPrivate::show_helper qwidget.cpp 7380 0x0081c41d
16 QWidget::setVisible qwidget.cpp 7594 0x0081cbbe
17 QDialog::setVisible qdialog.cpp 739 0x00c60f78
18 QWidget::show qwidget_simulator.cpp 889 0x00833a26
19 QDialog::exec qdialog.cpp 543 0x00c6060f
20 QMessageBoxPrivate::showOldMessageBox qmessagebox.cpp 1906 0x00c7fdab
...

this is the backtrace. what am it doing wrong here?

Upvotes: 0

Views: 483

Answers (2)

snoofkin
snoofkin

Reputation: 8895

Your signal doesnt have the same signature as your slot: clicked(QModelIndex)) = Singal. showMessage() = Slot.

Turn your slot to be: showMessage(QModelIndex)

Upvotes: 1

Stephen Chu
Stephen Chu

Reputation: 12832

The slot has to have the same signature as the signal. You can't connect a signal taking a parameter to a slot that's expecting none. Add that QModelIndex parameter to showMessage():

connect(view,SIGNAL(clicked(QModelIndex)),this,SLOT(showMessage(QModelIndex)));

void MainWindow::showMessage(QModelIndex)
{
    QMessageBox::information(this,"info","info",QMessageBox::Ok,0);
}

Upvotes: 3

Related Questions