Results 1 to 7 of 7

Thread: signals and slots problem

  1. #1
    Join Date
    Feb 2008
    Posts
    47
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Post signals and slots problem

    hi,
    If my lineedit control changes then a message has to be displayed.
    I have dont like this.

    Qt Code:
    1. public slots:
    2. OnChangelineedit();
    3.  
    4. connect(lineedit1, SIGNAL(cursorPositionChanged(0,1)),
    5. this, SLOT(OnChangelineedit()));
    To copy to clipboard, switch view to plain text mode 


    But i am getting error"
    Object::connect: No such signal QLineEdit::cursorPositionChanged(0,1)
    Object::connect: (sender name: 'lineedit1)
    Object::connect: (receiver name: 'dialog')".
    What is wrong with my code.
    Last edited by jpn; 27th February 2008 at 06:46. Reason: missing [code] tags

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: signals and slots problem

    I recommend reading about signals and slots. You can't put parameter names or values but only parameter types in connect statement.
    J-P Nurmi

  3. #3
    Join Date
    Dec 2007
    Posts
    4
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: signals and slots problem

    How about this...

    Qt Code:
    1. connect(lineedit1, SIGNAL(cursorPositionChanged(int, int)), this, SLOT(OnChangelineedit()));
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Mar 2008
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: signals and slots problem

    Hello,

    I'm using Eclipse and QT4 and I get exactly the same problem but the previous post doesn't really help very much.

    Qt Code:
    1. #ifndef TEST_QT_H
    2. #define TEST_QT_H
    3.  
    4. #include <QtGui/QWidget>
    5. #include "ui_test_qt.h"
    6.  
    7. class test_qt : public QWidget
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. test_qt(QWidget *parent = 0);
    13. ~test_qt();
    14.  
    15. private:
    16. Ui::test_qtClass ui;
    17.  
    18. public slots:
    19. void test();
    20. };
    21.  
    22. #endif // TEST_QT_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "test_qt.h"
    2.  
    3. test_qt::test_qt(QWidget *parent)
    4. : QWidget(parent)
    5. {
    6. ui.setupUi(this);
    7. connect(ui.pButton, SIGNAL(clicked()), ui.label, SLOT(test()));
    8. }
    9.  
    10. test_qt::~test_qt()
    11. {
    12.  
    13. }
    14.  
    15. void test_qt::test()
    16. {
    17. ui.label->setText("GO");
    18. }
    To copy to clipboard, switch view to plain text mode 

    I get this error:

    Qt Code:
    1. Object::connect: No such slot QLabel::test()
    2. Object::connect: (sender name: 'pButton')
    3. Object::connect: (receiver name: 'label')
    To copy to clipboard, switch view to plain text mode 

    can somebody help me on this ?
    thanks

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: signals and slots problem

    You are passing an incorrect receiver to the connect statement. QLabel does not have such slot as "test()". The test_qt class written by you does. So you should not pass "ui.label" but something else to the connect statement.
    J-P Nurmi

  6. #6
    Join Date
    Nov 2008
    Posts
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11

    Default Re: signals and slots problem

    Hell I have a similar problem, the error message I get is:
    Object::connect: No such slot QWidget::adminstart()

    If I add Q_OBJECT to my class, I get the following error msg when I type "make"
    ndefined symbols:
    "vtable for harpWin", referenced from:
    __ZTV7harpWin$non_lazy_ptr in harpwin.o
    ld: symbol(s) not found
    collect2: ld returned 1 exit status

    Here is my code (all in one file ):

    Qt Code:
    1. class harpWin : public QWidget
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. harpWin(QWidget *parent = 0);
    7. ~harpWin();
    8.  
    9. QGraphicsView *graphicsView;
    10. QPushButton *adminButton;
    11. QPushButton *measureButton;
    12. QPushButton *viewButton;
    13. QPushButton *quitButton;
    14. QVBoxLayout *vboxLayout;
    15. QHBoxLayout *hboxLayout;
    16.  
    17. public slots:
    18. void adminstart();
    19. };
    20.  
    21. harpWin::harpWin( QWidget *parent)
    22. : QWidget(parent)
    23. {
    24. setWindowTitle("Harp Win0");
    25. vboxLayout = new QVBoxLayout();
    26. hboxLayout = new QHBoxLayout();
    27.  
    28. graphicsView = new QGraphicsView(this);
    29. adminButton = new QPushButton("Admin", this);
    30. adminButton->setDefault(true);
    31. measureButton = new QPushButton("Measure", this);
    32. viewButton = new QPushButton("View", this);
    33. quitButton = new QPushButton("&Quit",this);
    34.  
    35. vboxLayout->addWidget(adminButton);//, 1, Qt::AlignRight);
    36. vboxLayout->addWidget(measureButton);
    37. vboxLayout->addWidget(viewButton);
    38. vboxLayout->addWidget(quitButton);
    39.  
    40. hboxLayout->addWidget(graphicsView, 1, Qt::AlignLeft);
    41. hboxLayout->addLayout(vboxLayout);
    42. setLayout(hboxLayout);
    43.  
    44. QObject::connect(quitButton, SIGNAL(clicked()), qApp, SLOT(quit()));
    45. connect(adminButton, SIGNAL(clicked()), this, SLOT( adminstart() ));
    46. QObject::connect(viewButton, SIGNAL(clicked()), qApp, SLOT(quit()));
    47. QObject::connect(measureButton, SIGNAL(clicked()), qApp, SLOT(quit()));
    48. }
    49.  
    50. harpWin::~harpWin()
    51. {
    52.  
    53. }
    54.  
    55. void harpWin::adminstart()
    56. {
    57. QString str = "\n clicked button\n";
    58. qDebug() << str;
    59. }
    60.  
    61.  
    62. int main(int argc, char *argv[])
    63. {
    64. QApplication app(argc, argv);
    65.  
    66. harpWin introWindow;
    67.  
    68. //introWindow.setWindowTitle("Absolute");
    69. introWindow.show();
    70.  
    71. return app.exec();
    72. }
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: signals and slots problem

    Quote Originally Posted by windsword View Post
    If I add Q_OBJECT to my class, I get the following error msg when I type "make"
    Do you use qmake? If yes, then you have to re-run it after you add Q_OBJECT macro.

Similar Threads

  1. signals and slots in plugins
    By anderl in forum Qt Programming
    Replies: 1
    Last Post: 10th October 2007, 13:57
  2. Memory Problem with SIGNALS and SLOTS
    By ^NyAw^ in forum Qt Programming
    Replies: 1
    Last Post: 19th March 2007, 20:39
  3. Nested signals and slots
    By vishva in forum Qt Programming
    Replies: 2
    Last Post: 18th August 2006, 09:47
  4. Problem with signals and slots
    By conexion2000 in forum Qt Programming
    Replies: 2
    Last Post: 23rd March 2006, 10:20
  5. Problem with Signals and Slots
    By Kapil in forum Newbie
    Replies: 11
    Last Post: 15th February 2006, 11:35

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.