Results 1 to 6 of 6

Thread: Signal and Slot Issue

  1. #1
    Join Date
    Mar 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Signal and Slot Issue

    I have created a programme with following files
    calculator.cpp
    Qt Code:
    1. #include "calculator.h"
    2. #include "ui_calculator.h"
    3. calculator::calculator(QWidget *parent)
    4. : QWidget(parent)
    5. {
    6. //Ui::calculatorClass *cal = new Ui::calculatorClass;
    7. //ui.setupUi(cal);
    8. ui.setupUi(this);
    9. connect (ui.spinBox1, SIGNAL(valueChanged(int)), this, SLOT(setValueLineEditSpinBox1(int & value)));
    10. /* connect (ui.spinBox2, SIGNAL(valueChanged(int)), calculator, SLOT(setValueLineEditSpinBox2(int & value))); */
    11. ui.lineEdit->setText("5");
    12. }
    13.  
    14. calculator::~calculator()
    15. {
    16.  
    17. }
    18. //slots
    19. void calculator::setValueLineEditSpinBox1(int &value)
    20. {
    21. ui.lineEdit->setText(QString::number(value+ui.spinBox2->value()));
    22. }
    23.  
    24.  
    25. void calculator::setValueLineEditSpinBox2(int &value)
    26. {
    27. ui.lineEdit->setText(QString::number(value+ui.spinBox1->value()));
    28. }
    To copy to clipboard, switch view to plain text mode 

    calculator. h file
    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. calculator(QWidget *parent = 0);
    13. ~calculator();
    14.  
    15. signals:
    16. /* int valuespinBox1();
    17.   int valuespinBox2();
    18. */
    19. public slots:
    20. void setValueLineEditSpinBox1(int &value);
    21. void setValueLineEditSpinBox2(int &value);
    22.  
    23.  
    24.  
    25. private:
    26. Ui::calculatorClass ui;
    27. };
    28.  
    29. #endif // CALCULATOR_H
    To copy to clipboard, switch view to plain text mode 

    main.cpp file
    Qt Code:
    1. #include "calculator.h"
    2. #include "ui_calculator.h"
    3.  
    4. #include <QtGui>
    5. #include <QApplication>
    6.  
    7. int main(int argc, char *argv[])
    8. {
    9. QApplication a(argc, argv);
    10. calculator w;
    11. w.show();
    12. return a.exec();
    13. }
    To copy to clipboard, switch view to plain text mode 

    I get an error as below
    No symbol "auto" in current context.
    warning: Object::connect: No such slot calculator::setValueLineEditSpinBox1(int&value)

    warning: Object::connect: (sender name: 'spinBox1')

    warning: Object::connect: (receiver name: 'calculatorClass'
    what is the issue in signal and slot not able to understand

    can anybody help please?

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Signal and Slot Issue

    try this
    Qt Code:
    1. connect (ui.spinBox1, SIGNAL(valueChanged(int)), this, SLOT(setValueLineEditSpinBox1(int)));
    2. ....
    3. public slots:
    4. void setValueLineEditSpinBox1(int value);
    5. void setValueLineEditSpinBox2(int value);
    To copy to clipboard, switch view to plain text mode 
    I don't see any sense form pass values in this form int &value for simple types of course.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Mar 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Signal and Slot Issue

    I had done that earlier
    The programm compiles properly but i do not get expected result

    I expect spinBox1 value to be added to spinBox2 value and displayed in lineedit
    spinBox value changes but the value is not displayed in the lineedit?
    where is the problem ?

    Help me

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Signal and Slot Issue

    did you make changes as I've posted above? if yes, then everything must work.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Signal and Slot Issue

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Mar 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Signal and Slot Issue

    Thanks Dear spirit and Dear Wysota

    Program Works!
    Thanks for helping a newbie

Similar Threads

  1. Connection of custon signals/slots
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 23rd December 2008, 07:04
  2. retrieving signal name in a slot
    By Baschterl in forum Qt Programming
    Replies: 2
    Last Post: 10th November 2008, 20:44
  3. Replies: 12
    Last Post: 18th September 2008, 15:04
  4. Signal & Slot editor
    By Ishark in forum Qt Tools
    Replies: 4
    Last Post: 28th May 2008, 15:20
  5. signal slot conection using a string, not a SLOT
    By rianquinn in forum Qt Programming
    Replies: 6
    Last Post: 5th February 2006, 18: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.