Results 1 to 14 of 14

Thread: How to pass a string to a function on a connect signal

  1. #1
    Join Date
    Nov 2010
    Posts
    22
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60 Maemo/MeeGo

    Default How to pass a string to a function on a connect signal

    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.


    Qt Code:
    1. connect(ui->lineEdit, SIGNAL(textChanged(QString)), ,SLOT(searchfunc(QString)));
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to pass a string to a function on a connect signal

    Most likely you are missing the third argument to connect(). At least the snippet you pasted here is missing it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Nov 2010
    Posts
    22
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60 Maemo/MeeGo

    Default Re: How to pass a string to a function on a connect signal

    Quote Originally Posted by wysota View Post
    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.

  4. #4
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to pass a string to a function on a connect signal

    hi,
    but i am little confused to what i should omplement there
    just put this pointer in the third arg
    Qt Code:
    1. connect(ui->lineEdit, SIGNAL(textChanged(QString)),this,SLOT(searchfunc(QString)));
    To copy to clipboard, switch view to plain text mode 

    hope it helps

    Bala

  5. #5
    Join Date
    Nov 2010
    Posts
    22
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60 Maemo/MeeGo

    Default Re: How to pass a string to a function on a connect signal

    Quote Originally Posted by BalaQT View Post
    hi,


    just put this pointer in the third arg
    Qt Code:
    1. connect(ui->lineEdit, SIGNAL(textChanged(QString)),this,SLOT(searchfunc(QString)));
    To copy to clipboard, switch view to plain text mode 

    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"

  6. #6
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to pass a string to a function on a connect signal

    maybe you forgot the Q_OBJECT macro? is searchfunc" defined as a slot?

  7. #7
    Join Date
    Nov 2010
    Posts
    22
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60 Maemo/MeeGo

    Default Re: How to pass a string to a function on a connect signal

    Quote Originally Posted by FelixB View Post
    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

    Qt Code:
    1. private slots:
    2. void searchfunc(QString searchtext);
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to pass a string to a function on a connect signal

    hi @jins ,

    as FelixB said, did u forget the Q_OBJECT macro.

    Qt Code:
    1. class myclass : public QWidget
    2. {
    3. Q_OBJECT
    4. private slots:
    5. void searchfunc(QString searchtext);
    6. }
    To copy to clipboard, switch view to plain text mode 

    did u include #include <QtGui>

    pls check

    pls post the class part
    Bala
    Last edited by BalaQT; 30th November 2010 at 12:17.

  9. #9
    Join Date
    Nov 2010
    Posts
    22
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60 Maemo/MeeGo

    Default Re: How to pass a string to a function on a connect signal

    Quote Originally Posted by BalaQT View Post
    hi @jins ,

    as FelixB said, did u forget the Q_OBJECT macro.

    Qt Code:
    1. class myclass : public QWidget
    2. {
    3. Q_OBJECT
    4. private slots:
    5. void searchfunc(QString searchtext);
    6. }
    To copy to clipboard, switch view to plain text mode 

    PLS CHECK

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


    Qt Code:
    1. class MainWindow : public QMainWindow
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. explicit MainWindow(QWidget *parent = 0);
    7. ~MainWindow();
    8.  
    9. private:
    10. Ui::MainWindow *ui;
    11.  
    12. DB* dbManager;
    13. bool opendb;
    14. QList<PersonData*> persondata;
    15.  
    16. private slots:
    17. void searchfunc(QString searchtext);
    To copy to clipboard, switch view to plain text mode 

  10. #10
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to pass a string to a function on a connect signal

    did u include #include <QtGui>

    Bala

  11. #11
    Join Date
    Nov 2010
    Posts
    22
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60 Maemo/MeeGo

    Default Re: How to pass a string to a function on a connect signal

    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.

  12. #12
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to pass a string to a function on a connect signal

    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

  13. #13
    Join Date
    Nov 2010
    Posts
    22
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60 Maemo/MeeGo

    Default Re: How to pass a string to a function on a connect signal

    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)

  14. #14
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Thumbs up Re: How to pass a string to a function on a connect signal

    Quote Originally Posted by jins View Post
    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

Similar Threads

  1. Replies: 2
    Last Post: 12th June 2010, 02:21
  2. Replies: 14
    Last Post: 1st December 2009, 20:45
  3. Connect button and pass QListView current index
    By been_1990 in forum Qt Programming
    Replies: 3
    Last Post: 30th November 2009, 16:20
  4. Replies: 4
    Last Post: 21st June 2009, 18:06
  5. How to pass a QComboBox to a function?
    By Ricardo_arg in forum General Programming
    Replies: 4
    Last Post: 9th March 2008, 22:16

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.