Results 1 to 4 of 4

Thread: Object::Connect problem

  1. #1
    Join Date
    Apr 2010
    Posts
    7
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Question Object::Connect problem

    dear all,
    i have some problem when make a connect function which is triggered when a QPushButton was clicked..
    the error is

    Object::connect: No such slot intervals::writeIntervals(4) in intervals.cpp:21

    i give my QPushButton as "Ok", and this is my source code

    source for my intervals.h :

    Qt Code:
    1. #ifndef INTERVALS_H
    2. #define INTERVALS_H
    3.  
    4. #include <QWidget>
    5. #include <QTextStream>
    6. #include <QFile>
    7. #include <QIODevice>
    8.  
    9. namespace Ui {
    10. class intervals;
    11. }
    12.  
    13. class intervals : public QWidget {
    14. Q_OBJECT
    15. public:
    16. intervals(QWidget *parent = 0);
    17. ~intervals();
    18. QString readInterval();
    19. void writeInterval(int a);
    20.  
    21. protected:
    22. void changeEvent(QEvent *e);
    23.  
    24. private:
    25. Ui::intervals *ui;
    26. QString value;
    27.  
    28. public slots:
    29. void writeIntervals(int a);
    30.  
    31. };
    32.  
    33. #endif
    To copy to clipboard, switch view to plain text mode 

    and intervals.cpp

    Qt Code:
    1. #include "intervals.h"
    2. #include "ui_intervals.h"
    3.  
    4. intervals::intervals(QWidget *parent) :
    5. QWidget(parent),
    6. ui(new Ui::intervals)
    7. {
    8. ui->setupUi(this);
    9. QFile file ("interval.txt");
    10. if (!file.exists("interval.txt"))
    11. {
    12. this->writeInterval(5);
    13. ui->IntervalEdit->setText(readInterval());
    14. }
    15. else
    16. {
    17. ui->IntervalEdit->setText(readInterval());
    18. }
    19.  
    20. qDebug("tes");
    21. connect(ui->Ok,SIGNAL(clicked()),this,SLOT(writeIntervals(4)));
    22. qDebug("tes2");
    23. }
    24.  
    25. void intervals::writeInterval(int a)
    26. {
    27. QFile file("interval.txt");
    28. if (file.open(QIODevice::WriteOnly | QIODevice::Text))
    29. {
    30. QTextStream out(&file);
    31. out << a << "\n";
    32. file.close();
    33. }
    34. }
    To copy to clipboard, switch view to plain text mode 

    May someone help me with this error?

  2. #2
    Join Date
    Apr 2010
    Posts
    2
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Object::Connect problem

    I'm not a QT expert, but I believe that you can not connect a signal to a slot unless they have the same function parameters.

    http://doc.trolltech.com/4.6/signalsandslots.html

    {
    connect(ui->Ok,SIGNAL(clicked()),this,SLOT(writeIntervalFOUR( )));
    }

    void intervals::writeIntervalFOUR()
    {
    writeInterval(4);

    }

    Also look into QButtonGroup if you want the int parameter

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

    geleven (6th April 2010)

  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 problem

    You can't pass values inside a connect statement. But I guess a look at QSignalMapper could be worth for you.

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

    geleven (6th April 2010)

  6. #4
    Join Date
    Apr 2010
    Posts
    7
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: Object::Connect problem

    Quote Originally Posted by Lykurg View Post
    You can't pass values inside a connect statement. But I guess a look at QSignalMapper could be worth for you.
    oh ok... i see the problem. Thanks for your help, Lykurg and Wysodava

Similar Threads

  1. Replies: 2
    Last Post: 20th September 2009, 02:52
  2. 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
  3. Object::connect: Parentheses expected, slot...
    By bnilsson in forum Qt Programming
    Replies: 5
    Last Post: 5th April 2008, 15:02
  4. Replies: 21
    Last Post: 5th January 2008, 15:44
  5. Replies: 3
    Last Post: 24th September 2007, 08:20

Tags for this Thread

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.