Results 1 to 20 of 20

Thread: Problem with slot

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    Feb 2009
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    3

    Default Re: Problem with slot

    Thanks, this problem is solved, but now come other problems.
    calc.h:18: error: ISO C++ forbids declaration of ‘QLCDNumber’ with no type
    calc.h:18: error: expected ‘;’ before ‘*’ token
    So I added the declaration of QLCDNumber class: class QLCDNumber;. and now are problems with the inside of the slot:
    calc.cpp:17: error: invalid use of member (did you forget the ‘&’ ?)
    How can I solve it?

    I think i solve this problem. I add to class Calc new variable int value, which stores the actual result of calculations and use display function.

    But... I have new problem...
    Here is my source code:
    Qt Code:
    1. //calc.h
    2.  
    3. #ifndef CALC_H
    4. #define CALC_H
    5.  
    6. #include <QtGui/QDialog>
    7.  
    8. class QLCDNumber;
    9. namespace Ui
    10. {
    11. class Calc;
    12. }
    13.  
    14. class Calc : public QDialog
    15. {
    16. Q_OBJECT
    17.  
    18. private:
    19. QLCDNumber *lcdNumber;
    20. QPushButton *seventhButton;
    21. QPushButton *eighthButton;
    22. QPushButton *ninethButton;
    23. QPushButton *divisionButton;
    24. QPushButton *fourthButton;
    25. QPushButton *fifthButton;
    26. QPushButton *sixthButton;
    27. QPushButton *additionButton;
    28. QPushButton *firstButton;
    29. QPushButton *secondButton;
    30. QPushButton *thirdButton;
    31. QPushButton *subtractionButton;
    32. QPushButton *zeroButton;
    33. QPushButton *sqrtButton;
    34. QPushButton *multiplicationButton;
    35. QPushButton *moduloButton;
    36. int value;
    37.  
    38. public:
    39. Calc(QWidget *parent = 0);
    40. ~Calc();
    41.  
    42. public slots:
    43. void setVal(const int &val);
    44.  
    45.  
    46.  
    47. private:
    48. Ui::Calc *ui;
    49. };
    50.  
    51. #endif // CALC_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "calc.h"
    2. #include "ui_calc.h"
    3.  
    4. Calc::Calc(QWidget *parent)
    5. : QDialog(parent), ui(new Ui::Calc)
    6. {
    7. ui->setupUi(this);
    8. connect(zeroButton, SIGNAL(clicked()), this, SLOT(setVal(0)));
    9. }
    10.  
    11. Calc::~Calc()
    12. {
    13. delete ui;
    14. }
    15.  
    16. void Calc::setVal(const int &val){
    17.  
    18. value*=10;
    19. value+=val;
    20. lcdNumber ->display(value);
    21. }
    To copy to clipboard, switch view to plain text mode 

    In the constructor I add the conection between zero button and LCDNumber. It should works, but in the console are errors:
    Segmentation fault
    I have no idea how to do this. Could anyone help me?
    It's harder than I thought at the beginning of lessons.

    I've read in documentation that the signal and slot parameters mustn't contain variable name, but only type, so how can I send the value, which is needed?
    Last edited by stefek; 28th February 2009 at 16:43.

Similar Threads

  1. How to declare SLOT as a parameter to member function?
    By QPlace in forum Qt Programming
    Replies: 2
    Last Post: 17th July 2018, 00:41
  2. Replies: 12
    Last Post: 18th September 2008, 15:04
  3. Tricky problem with ARGB widget / UpdateLayeredWindow
    By nooky59 in forum Qt Programming
    Replies: 3
    Last Post: 21st February 2008, 10:35
  4. Thread, Timer and Socket. Comuication problem
    By ^NyAw^ in forum Qt Programming
    Replies: 6
    Last Post: 17th January 2008, 16:48
  5. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45

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.