Results 1 to 9 of 9

Thread: Object::connect: No such slot

  1. #1
    Join Date
    Jan 2013
    Posts
    17
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Object::connect: No such slot

    Hi, my program is about animating the motion of the upper arm. currently there is 4 objects on my GUI. one is panelGL which displays the animation. then there is the horizontal slider, play button and reset button. i will first like to connect the slider to my panelGL so that the animation can be controlled by the slider. then i will like to connect the reset button and play button to the slider. the reset button will reset the value of the slider and thus also reset the animation to the initial position. the play button will start moving the slider, thus resulting in the animation of the arm from start till the end.

    the problem i'm currently facing is as follows
    Qt Code:
    1. Object::connect: No such slot MyPanelOpenGL::counterChanged(int) in mainwindow.cpp:19
    2. Object::connect: (sender name: 'horizontalSlider')
    3. Object::connect: (receiver name: 'panelGL')
    4. Object::connect: No such slot QSlider::SetSliderValue() in mainwindow.cpp:20
    5. Object::connect: (sender name: 'ResetButton')
    6. Object::connect: (receiver name: 'horizontalSlider')
    7. Object::connect: No such slot QSlider::animate() in mainwindow.cpp:21
    8. Object::connect: (sender name: 'PlayButton')
    9. Object::connect: (receiver name: 'horizontalSlider')
    To copy to clipboard, switch view to plain text mode 

    Any help will be appreciated and my code is
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include <QTimer>
    4. #include "main.h"
    5. #include <QDebug>
    6.  
    7.  
    8.  
    9. extern QList<FileData> points;
    10. int counter=0;
    11.  
    12. MainWindow::MainWindow(QWidget *parent) :
    13. QMainWindow(parent),
    14. ui(new Ui::MainWindow)
    15. {
    16. ui->setupUi(this);
    17.  
    18.  
    19. connect(ui->horizontalSlider, SIGNAL(valueChanged(int)),ui->panelGL, SLOT(counterChanged(int)));
    20. connect(ui->ResetButton,SIGNAL(clicked()), ui->horizontalSlider, SLOT(SetSliderValue()));
    21. connect(ui->PlayButton,SIGNAL(clicked()), ui->horizontalSlider, SLOT(animate()));
    22.  
    23. }
    24.  
    25. void MainWindow::counterChanged(int counter)
    26. {
    27. counter = ui->horizontalSlider->value();
    28. }
    29.  
    30. void MainWindow::SetSliderValue()
    31. {
    32.  
    33. ui->horizontalSlider->setValue(0);
    34.  
    35. }
    36.  
    37.  
    38. void MainWindow::animate()
    39. {
    40.  
    41. if ( counter < points.size()-1 )
    42. {
    43. QTimer *timer = new QTimer(this);
    44. connect(timer, SIGNAL(timeout()), this, SLOT(update()));
    45. counter++;
    46. timer->start(1000);
    47.  
    48. }
    49. }
    50.  
    51.  
    52.  
    53.  
    54. MainWindow::~MainWindow()
    55. {
    56. delete ui;
    57. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Object::connect: No such slot

    For QSlider the slot is setSliderPosition or setValue and both need parameters passed (so can't be connected directly with clicked, so connect clicked to a slot of yours from where you can access whatever value you want to set to the slider) and QSlider doesn't have an animate().

    And make sure that panelGL has counterChanged(int)

  3. The following user says thank you to Zlatomir for this useful post:

    kango (20th February 2013)

  4. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Object::connect: No such slot

    it has to be
    Qt Code:
    1. connect(ui->horizontalSlider, SIGNAL(valueChanged(int)),this, SLOT(counterChanged(int)));
    2. connect(ui->ResetButton,SIGNAL(clicked()), this, SLOT(SetSliderValue()));
    3. connect(ui->PlayButton,SIGNAL(clicked()), this, SLOT(animate()));
    To copy to clipboard, switch view to plain text mode 

  5. The following 2 users say thank you to Lykurg for this useful post:

    kango (20th February 2013), Zlatomir (20th February 2013)

  6. #4
    Join Date
    Jan 2013
    Posts
    17
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Object::connect: No such slot

    Quote Originally Posted by Lykurg View Post
    it has to be
    Qt Code:
    1. connect(ui->horizontalSlider, SIGNAL(valueChanged(int)),this, SLOT(counterChanged(int)));
    2. connect(ui->ResetButton,SIGNAL(clicked()), this, SLOT(SetSliderValue()));
    3. connect(ui->PlayButton,SIGNAL(clicked()), this, SLOT(animate()));
    To copy to clipboard, switch view to plain text mode 
    If i replace with "this", how do they know which object the slots belong to?

  7. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Object::connect: No such slot

    They belong to "this". The third argument is the receiver.

  8. The following user says thank you to Lykurg for this useful post:

    kango (20th February 2013)

  9. #6
    Join Date
    Jan 2013
    Posts
    17
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Object::connect: No such slot

    Quote Originally Posted by Zlatomir View Post
    For QSlider the slot is setSliderPosition or setValue and both need parameters passed (so can't be connected directly with clicked, so connect clicked to a slot of yours from where you can access whatever value you want to set to the slider) and QSlider doesn't have an animate().

    And make sure that panelGL has counterChanged(int)
    can you provide an example on connecting click() to a slot if i need to reset the slider's value to 0?

    setSliderPosition(), counterChanged() and animate() are custom slots which i have created. Can i not use custom slots?

    Quote Originally Posted by Lykurg View Post
    They belong to "this". The third argument is the receiver.
    sorry but i don't really get what you mean. shouldn't i connect the signal of the object i'm sending from to the slot of the other object i'm receiving?
    what do you mean the third argument is the receiver?

  10. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Object::connect: No such slot

    Ok, explained a little bit more: you have two classes derived from QObject which is needed that signal and slots works.
    Qt Code:
    1. SomeClass *sender = new SomeClass;
    2. SomeOtherClass *receiver = new SomeOtherClass;
    To copy to clipboard, switch view to plain text mode 
    Now if you want connect them you can connect a signal of sender to a slot of reciever. (Of course sender and receiver can be the same.) So you do
    Qt Code:
    1. connect(sender, SIGNAL(signalOfSender()), receiver, SLOT(slotOfReceiver()));
    To copy to clipboard, switch view to plain text mode 

    In your case you want connect to slots of the same class where you establish the connection. So you need a pointer like "sender". This is "this" in your case.

    EDIT: "this" is a pointer to the class where you use "this".

  11. #8
    Join Date
    Jan 2013
    Posts
    17
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Object::connect: No such slot

    sorry but i still don't really get what you mean as i'm new to programming? how do the signal know which object the slots belong to if i use "this"?
    is there alot more changes needed to be done to my code?

  12. #9
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Object::connect: No such slot

    As I told: you only have to use "this". Then your program should work.

    Another try: The signal knows nothing. It is simply emitted. With the connect syntax you "catch" a signal defining the actual initialization of a class (pointer) and the signal. (sender and signalOfSender in my example) And then you bind that signal to a slot which is again defined by a pointer to a class and its slot (receiver and slotOfReceiver).
    In your case you want to connect to slots of MainWindow. Therefore you need a pointer to it which you don't have. Therefore use "this" which is a pointer to the actual instance of MainWindow.

  13. The following user says thank you to Lykurg for this useful post:

    kango (20th February 2013)

Similar Threads

  1. Replies: 4
    Last Post: 28th October 2011, 05:09
  2. Anoying problem, Object::connect: No such slot
    By Aslund in forum Qt Programming
    Replies: 1
    Last Post: 20th March 2011, 08:09
  3. Connect signal from base to slot of sub-sub-object
    By donglebob in forum Qt Programming
    Replies: 15
    Last Post: 30th October 2008, 19:54
  4. Object::connect: Parentheses expected, slot...
    By bnilsson in forum Qt Programming
    Replies: 5
    Last Post: 5th April 2008, 15:02
  5. Replies: 21
    Last Post: 5th January 2008, 15:44

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
  •  
Qt is a trademark of The Qt Company.