Results 1 to 2 of 2

Thread: connect - how to make function recieving argument

  1. #1
    Join Date
    Jan 2009
    Posts
    3
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default connect - how to make function recieving argument

    Hello,

    I'm new in Qt programming. I've made a simple program:

    calculator.h:

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

    calculator.cpp:
    Qt Code:
    1. #include "calculator.h"
    2.  
    3.  
    4. Calculator::Calculator(QWidget *parent)
    5. : QWidget(parent)
    6. {
    7. ui.setupUi(this);
    8. connect( ui.button_0, SIGNAL( clicked() ), this, SLOT( add_digit_0(text) ) );
    9. }
    10.  
    11. Calculator::~Calculator()
    12. {
    13.  
    14. }
    15. void Calculator::add_digit_0(QString &text)
    16. {
    17.  
    18. text+='0';
    19.  
    20. ui.display->setText( text );
    21. }
    To copy to clipboard, switch view to plain text mode 

    'dispaly' is QLineEdit and 'button_0' is a QPushButton object.

    Compiler shows no errors, but when I run a program nothing happens (there is no text in display unit). I tested it a thousand times and it seems that SLOT( add_digit(text) ) does not want to recieve any arguments, because when I write function like...

    Qt Code:
    1. void Calculator::add_digit_0()
    2. {
    3. ui.display->setText("TEXT");
    4. }
    To copy to clipboard, switch view to plain text mode 

    ...everything works.

    Any Ideas how to make it work?

    Thanks for help.

    PS
    Sorry for the topic name, but I have no idea what name should it be.
    Last edited by pitterb; 12th January 2009 at 17:47.

  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: connect - how to make function recieving argument

    See QSignalMapper. Pay attention to the example in the detailed description.

    You cannot put statements or variables inside SIGNAL() or SLOT() macros. See signals and slots for more details how they work.
    J-P Nurmi

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

    pitterb (12th January 2009)

Similar Threads

  1. QPSQL problem
    By LoneWolf in forum Installation and Deployment
    Replies: 60
    Last Post: 4th November 2009, 14:22
  2. QPSQL driver in windows
    By brevleq in forum Installation and Deployment
    Replies: 31
    Last Post: 14th December 2007, 12:57
  3. how to add static library into qmake
    By Namrata in forum Qt Tools
    Replies: 1
    Last Post: 20th November 2007, 17:33
  4. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  5. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52

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.