Page 2 of 2 FirstFirst 12
Results 21 to 38 of 38

Thread: A little calculator problem

  1. #21
    Join Date
    Feb 2010
    Posts
    42
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: A little calculator problem

    ok i ran qmake in the folder of main.cpp then I pressed rebuild in Code::Blocks and it gave me the same error.

  2. #22
    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: A little calculator problem

    Did you implement the class destructor?
    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.


  3. #23
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: A little calculator problem

    Quote Originally Posted by bijan311 View Post
    ok i ran qmake in the folder of main.cpp then I pressed rebuild in Code::Blocks and it gave me the same error.
    Dump Code::Blocks, download Qt Creator. It will make your life easier. Once you have learned the basics, you can go back to Code::Blocks if you wish.

    (For example, in Qt Creator there is no need for a console as you can do everything from inside the IDE)

  4. #24
    Join Date
    Feb 2010
    Posts
    42
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: A little calculator problem

    ok so I have installed QT Creator.

    and what is a class destructor.

  5. #25
    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: A little calculator problem

    Quote Originally Posted by bijan311 View Post
    and what is a class destructor.
    Ouch... we didn't learn C++, did we?

    http://en.wikipedia.org/wiki/Destruc...puter_science)
    http://www.parashift.com/c++-faq-lite/dtors.html
    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. #26
    Join Date
    Feb 2010
    Posts
    42
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: A little calculator problem

    I did learn c++ from
    cprogramming.com
    I just never had a good understanding of classes.

  7. #27
    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: A little calculator problem

    So you were learning C++ but didn't learn it. It's all about classes. It's like you were learning a language but never had a good understanding of words... I suggest you correct that mistake now.
    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.


  8. #28
    Join Date
    Feb 2010
    Posts
    42
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: A little calculator problem

    well actually, I got a better understanding of classes when reading this thread...

  9. #29
    Join Date
    Feb 2010
    Posts
    42
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: A little calculator problem

    OK, I got it to compile but when i press execute the LCDNumber thing doesn't change.
    here is the cofr
    Qt Code:
    1. #include <QApplication>
    2. #include <QPushButton>
    3. #include <QLabel>
    4. #include <QSpinBox>
    5. #include <QLCDNumber>
    6. #include <QHBoxLayout>
    7. #include <QVBoxLayout>
    8.  
    9. class calculator : public QWidget{
    10.  
    11. public:
    12. calculator(QWidget *parent = 0) : QWidget(parent)
    13. {
    14. equal = new QPushButton("Execute");
    15. num1 = new QSpinBox;
    16. num2 = new QSpinBox;
    17. answer = new QLCDNumber;
    18.  
    19. QHBoxLayout *layout = new QHBoxLayout;
    20. layout->addWidget(num1);
    21. layout->addWidget(num2);
    22. layout->addWidget(answer);
    23. QVBoxLayout *mainLayout = new QVBoxLayout(this);
    24. mainLayout->addLayout(layout);
    25. mainLayout->addWidget(equal);
    26.  
    27. QObject::connect(equal, SIGNAL(clicked()), answer, SLOT(minus()));
    28. }
    29. public slots:
    30. void minus(){
    31. answer->display(num1->value()-num2->value());
    32. }
    33. private:
    34. QPushButton *equal;
    35. QSpinBox *num1;
    36. QSpinBox *num2;
    37. QLCDNumber *answer;
    38. };
    39.  
    40. int main(int argc, char *argv[])
    41. {
    42. QApplication app(argc, argv);
    43. calculator w;
    44.  
    45. w.show();
    46. return app.exec();
    47. }
    To copy to clipboard, switch view to plain text mode 

  10. #30
    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: A little calculator problem

    Quote Originally Posted by bijan311 View Post
    OK, I got it to compile but when i press execute the LCDNumber thing doesn't change.
    This doesn't surprise me as your code is not correct. Please open Qt Reference and read what arguments should you pass to connect(). Currently you miss some basic understanding of the signal/slot mechanism. Besides, you have already been given a working solution.
    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.


  11. #31
    Join Date
    Feb 2010
    Posts
    42
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: A little calculator problem

    I only made a few changes. I got rid of the Q_Object macro because with it the program wouldn't link to the .exe file. I tried to make a .moc file by using qmake in the directory of the program, the only files that are there are:

    Calculator Gui.depend
    Calculator Gui.layout
    Calculator Gui.pro
    Calculator Gui.pro.user
    file
    file.Debug
    file.Release
    Makefile
    Makefile.Debug
    Makefile.Release

    thank you.

  12. #32
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: A little calculator problem

    Watch the output window in Qt Creator, it'll tell you what your doing wrong. I can see an instant problem with your connect() call.

  13. #33
    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: A little calculator problem

    Quote Originally Posted by bijan311 View Post
    I only made a few changes. I got rid of the Q_Object macro because with it the program wouldn't link to the .exe file.
    This macro wasn't there because it looks nice, placing it there had its purpose. I really really suggest you read a bit of docs before you start programming with Qt. At least go through the tutorial.
    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.


  14. #34
    Join Date
    Feb 2010
    Location
    Hungary
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: A little calculator problem

    QtCreator maybe can help you.

  15. #35
    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: A little calculator problem

    Quote Originally Posted by sutee84 View Post
    QtCreator maybe can help you.
    No, Qt Creator won't help him understand what he is doing.
    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.


  16. #36
    Join Date
    Feb 2010
    Location
    Hungary
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: A little calculator problem

    You're right, but it's easier to connect signals and slots in QtCreator on the right way.

  17. #37
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: A little calculator problem

    Quote Originally Posted by sutee84 View Post
    You're right, but it's easier to connect signals and slots in QtCreator on the right way.
    Yes, if you know where the signals and slots need to be connected, but if you don't know that it could just become even more confusing when it doesn't let you do what you think is correct (like connecting a signal to a integer variable).

    Reading the documentation or tutorial is a must before attempting anything, even a simple calculator program. If your a seasoned developer, the tutorial will probably take you about 10 minutes to go through.

  18. #38
    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: A little calculator problem

    Quote Originally Posted by sutee84 View Post
    You're right, but it's easier to connect signals and slots in QtCreator on the right way.
    But you have to choose the right object as the source and destination of the signal. Without that Creator will not be helpful in any way other than not listing the signals and slot you'd like to connect which suggests you did something wrong. But then the compiler/Qt pair do exactly the same thing.
    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.


Similar Threads

  1. amscalc - calculator for ammoniumsulfate precipitation
    By nikau in forum Qt-based Software
    Replies: 1
    Last Post: 30th October 2008, 06:55
  2. Calculator Builder Example
    By janus in forum Newbie
    Replies: 1
    Last Post: 19th April 2008, 10:23
  3. From calculator: how to draw
    By mattia in forum Newbie
    Replies: 1
    Last Post: 26th October 2007, 12:22
  4. Need help with a basic calculator
    By Morea in forum Qt Programming
    Replies: 7
    Last Post: 25th March 2006, 20:18

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.