Results 1 to 8 of 8

Thread: wrong connection? program crashes altough it compiles

  1. #1
    Join Date
    Aug 2008
    Posts
    52
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default wrong connection? program crashes altough it compiles

    I am trying to display a lineedit for 3 seconds and then make it disappear. The problem is that altough the code compiles properly the program crasses when i run it and sends the following error:
    Object::connect: No such slot kentriko::diagrafi(grami2)
    Object::connect: (receiver name: 'kentrikoClass')
    the code:
    Qt Code:
    1. #ifndef KENTRIKO_H
    2. #define KENTRIKO_H
    3.  
    4. #include <QtGui/QMainWindow>
    5. #include "ui_kentriko.h"
    6.  
    7. class kentriko : public QMainWindow
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. kentriko(QWidget *parent = 0);
    13. ~kentriko();
    14.  
    15. public slots:
    16. void anixe();
    17. void diagrafi(QLineEdit* grami2);
    18.  
    19. private:
    20. Ui::kentrikoClass ui;
    21. };
    22.  
    23. #endif // KENTRIKO_H
    24.  
    25.  
    26. and the implementation:
    27. #include "kentriko.h"
    28. #include <QTimer>
    29. kentriko::kentriko(QWidget *parent)
    30. : QMainWindow(parent)
    31. {
    32. ui.setupUi(this);
    33. connect(ui.grami,SIGNAL(textChanged ( const QString &)),this,SLOT(anixe()));
    34. //
    35. }
    36.  
    37. void kentriko::anixe(){
    38. QLineEdit* grami2 = new QLineEdit(this);
    39. grami2->setObjectName(QString::fromUtf8("grami2"));
    40. grami2->setGeometry(QRect(60, 80, 180, 25));
    41. grami2->show();
    42. QTimer::singleShot(3000, this, SLOT(diagrafi(grami2 )));
    43. ui.label->setText("kalispera");
    44. }
    45.  
    46. void kentriko::diagrafi(QLineEdit* grami2){
    47. grami2->hide();
    48. }
    To copy to clipboard, switch view to plain text mode 

    Any ideas about why is the program crasing when the timer expires?

    Many thanks in advance.
    Regards.

  2. #2
    Join Date
    Jul 2008
    Posts
    139
    Thanks
    9
    Thanked 18 Times in 15 Posts
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: wrong connection? program crashes altough it compiles

    Hi,
    I have had this happen many times. The QTcore cannot find the signal/slot that is requested. It cannot tell this during compile time, so it will warn you later during the debug of what went wrong. It is telling you that it cannot find the slot in your class (diagrafi).
    Object::connect: No such slot kentriko::diagrafi(grami2)
    Object::connect: (receiver name: 'kentrikoClass')
    Is there another object that is using this slot? maybe the other object cannot see this slot?

  3. #3
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: wrong connection? program crashes altough it compiles

    If QTimer emitted a signal with a QLineEdit* paran, then (and only then)

    wrong
    Qt Code:
    1. QTimer::singleShot(3000, this, SLOT(diagrafi(grami2 )));
    To copy to clipboard, switch view to plain text mode 

    right (not really right, because of big if)
    Qt Code:
    1. QTimer::singleShot(3000, this, SLOT(diagrafi(QLineEdit*)));
    To copy to clipboard, switch view to plain text mode 


    Alas, it does not emit a signal with such a param.
    Therefore:
    right:
    Qt Code:
    1. QTimer::singleShot(3000, this, SLOT(diagrafi()));
    2.  
    3. void kentriko::anixe()
    4. {
    5. grami2 = new QLineEdit(this); // provide a member variable grami2
    6. grami2->setObjectName(QString::fromUtf8("grami2"));
    7. grami2->setGeometry(QRect(60, 80, 180, 25));
    8. grami2->show();
    9. QTimer::singleShot(3000, this, SLOT(diagrafi()));
    10. ui.label->setText("kalispera");
    11. }
    12. void kentriko::diagrafi()
    13. {
    14. grami2->hide();
    15. }
    To copy to clipboard, switch view to plain text mode 


    HTH

  4. #4
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: wrong connection? program crashes altough it compiles

    Your connect is incorrect. The documentation says
    "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.)"
    I'm a rebel in the S.D.G.

  5. #5
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: wrong connection? program crashes altough it compiles

    exactly. and what is the signature of QTimer::timeout()....?
    I do not see a QLineEdit there... (and shorter than no arguments at all is usually a bit of a problem, too).

  6. #6
    Join Date
    Aug 2008
    Posts
    52
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: wrong connection? program crashes altough it compiles

    caduel and lyuts many thanks for the reply.

    It appears that you are right caduel. The only way to do that is to make qlineedit object visible to the entire scope of the class and then hide it without passing anyting from the slot.

    But really if one cant pass arguments through the signal slot mechanism then this is a big mistake. I am suprised that it hasnt been mentioned before.

    Are we sure that this is hot it works. From my reading we are right.

    Regards.

  7. #7
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: wrong connection? program crashes altough it compiles

    You can pass arguments... when invoking a signal: the signal has to emit the arguments.
    You can not define values (for a slot's arguments) when creating the connection.

    (If you want to do that: you can use Boost.Signals and 'bind' the constants to your function. See www.boost.org; Boost.Signals and Qt signals are a similar concept and may be used in parallel. You have to deacivate Qt keyword with CONFIG += no_keywords in your .pro file, otherwise the keyword "signals" and the Boost signals headers are in conflict.)

  8. #8
    Join Date
    Aug 2008
    Posts
    52
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: wrong connection? program crashes altough it compiles

    thank for the reply.

    I just had a look on the boost library.
    Is it a cross platform library?
    For my case how can i use the bind function to pass arguments to the slot?
    Can i use both the connect and the boost::bind function on the same code?

    Can you please modify the code in order to use the boos::bind insted of the connect?

    Many thanks in advance.

Similar Threads

  1. Client/Server Error: BadIDChoice
    By 3nc31 in forum Qt Programming
    Replies: 5
    Last Post: 27th November 2007, 10:22
  2. QT MySQL
    By sabeeshcs in forum Newbie
    Replies: 6
    Last Post: 12th January 2007, 04:19

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.