PDA

View Full Version : How to pass a string to a function on a connect signal



jins
30th November 2010, 11:29
Hi am trying pass a string to a function that searches a database, as soon as a user types in the lineedit.

I am watching the linedit for any text change then want to send text in the lineedit to a function called searchfunc.

What am i missing or doing wrong.



connect(ui->lineEdit, SIGNAL(textChanged(QString)), ,SLOT(searchfunc(QString)));

wysota
30th November 2010, 11:34
Most likely you are missing the third argument to connect(). At least the snippet you pasted here is missing it.

jins
30th November 2010, 11:43
Most likely you are missing the third argument to connect(). At least the snippet you pasted here is missing it.

Yes you are correct, but i am little confused to what i should omplement there as i just want to pass a simple string to a function, all teh examples i have seen on the web are not showing this.

BalaQT
30th November 2010, 11:47
hi,

but i am little confused to what i should omplement there

just put this pointer in the third arg

connect(ui->lineEdit, SIGNAL(textChanged(QString)),this,SLOT(searchfunc( QString)));

hope it helps

Bala

jins
30th November 2010, 11:53
hi,


just put this pointer in the third arg

connect(ui->lineEdit, SIGNAL(textChanged(QString)),this,SLOT(searchfunc( QString)));

hope it helps

Bala

Hi Bala

Thank you very much for replying. I tried that before and i am still get same error for the connect code.

"expected constructor, destructor or type conversion before ' ( ' token"

FelixB
30th November 2010, 12:02
maybe you forgot the Q_OBJECT macro? is searchfunc" defined as a slot?

jins
30th November 2010, 12:06
maybe you forgot the Q_OBJECT macro? is searchfunc" defined as a slot?

Hi FelixB

This is what i have in the mainwindow.h file


private slots:
void searchfunc(QString searchtext);

BalaQT
30th November 2010, 12:12
hi @jins ,

as FelixB said, did u forget the Q_OBJECT macro.


class myclass : public QWidget
{
Q_OBJECT
private slots:
void searchfunc(QString searchtext);
}


did u include #include <QtGui>

pls check

pls post the class part
Bala

jins
30th November 2010, 12:17
hi @jins ,

as FelixB said, did u forget the Q_OBJECT macro.


class myclass : public QWidget
{
Q_OBJECT
private slots:
void searchfunc(QString searchtext);
}


PLS CHECK

Bala

I have the QObject specified already, I am sorry i didnt paste the entire code before here it is:



class MainWindow : public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();

private:
Ui::MainWindow *ui;

DB* dbManager;
bool opendb;
QList<PersonData*> persondata;

private slots:
void searchfunc(QString searchtext);

BalaQT
30th November 2010, 12:18
did u include #include <QtGui>

Bala

jins
30th November 2010, 12:23
Hi Bala

I have #include <QtGui/QApplication > in main.cpp but just in case i have also added #include <QtGui> and i am still getting the error message.

BalaQT
30th November 2010, 12:32
hi,
how u r compiling?
try qmake-qt4

clean all the files, delete all the obj files and then try qmake-qt4


shall i know where u r using connect?
pls post the connect block

Bala

jins
30th November 2010, 12:36
Ok i will like to publically apoligise for my stupidity, i had cut and pasted the connect line outside MainWindow::MainWindow setup and didnt realise. I am so sorry for wasting your time but also very greatful for all your help and advice (BalaQT the third argument you advised worked a dream)

BalaQT
30th November 2010, 12:47
Ok i will like to publically apoligise for my stupidity, i had cut and pasted the connect line outside MainWindow::MainWindow setup and didnt realise. I am so sorry for wasting your time but also very greatful for all your help and advice (BalaQT the third argument you advised worked a dream)

hi jins,
its nice the problem is solved
all the best for ur work.
Bala