PDA

View Full Version : Slot doesn't seem to work



waynew
8th November 2009, 01:37
A pushbutton, pbSave, in the StnInfoDialog form needs to call the slot insertInfo in the stninfodialog.cpp passing the value of the form field 'call'
Here is the code:



#include "stninfodialog.h"
#include "ui_stninfodialog.h"
#include "makestndb.h"
#include "insertstninfo.h"
#include <QDebug>

StnInfoDialog::StnInfoDialog(QWidget *parent) :
QDialog(parent),
m_ui(new Ui::StnInfoDialog)
{
m_ui->setupUi(this);

connect(m_ui->pbSave, SIGNAL(clicked(bool)),
this, SLOT(insertInfo(m_ui->call->text())));
}
}

void StnInfoDialog::insertInfo(QString mycall)
{
InsertStnInfo insert;
insert.insertStnInfo(mycall);
}


Problem is, the slot never gets called when pbSave is clicked.
Can someone please show me what I am doing wrong?

gboelter
8th November 2009, 06:46
[QUOTE=waynew;121836]



connect(m_ui->pbSave,
SIGNAL(clicked(bool)), this,
SLOT(insertInfo(m_ui->call->text())));


Try this:



connect( m_ui->pbSave,
SIGNAL( clicked() ), this,
SLOT( insertInfo( ) ) );


You can't submit a parameter with insertInfo(). You could create your own signal, but may be a private variable will do the job.

waynew
8th November 2009, 12:20
Tnx gboelter - got it working ok now by eliminating the parameter and getting the form field value while in insertinfo, then passing it to the insert database method.

jbiloba
10th November 2009, 09:54
From Qt Doc:

Note that the signal and slots parameters must not contain any variable names, only the type.

The signature of a signal must match the signature of the receiving slot. (In fact a slot may have a shorter signature than the signal it receives because it can ignore extra arguments.

So:

use only type: Qstring, int and not QString dummy or int Bignumber, only QString or int.
If u can use the same number of parameters too.


Hope this help