QT GUI Toolkit: beginer

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jpenguin
    New Member
    • Aug 2007
    • 41

    QT GUI Toolkit: beginer

    So I am learning QT. But I can't seem to ge past 2 errors that seem to make no sense to me, "error "ui" was not declared in this scope". what get me is that I have the same thing on the next line, but no error...

    simplecalc.cpp
    Code:
    #include <QtGui> 
     #include <QMessageBox>  
    #include "simplecalc.h"   
    //using namespace UI; 
    simplecalc::simplecalc(QWidget *parent) 	: QDialog(parent)
     {
           ui.setupUi(this);     //error
           connect( ui.calc, SIGNAL( clicked() ), this, SLOT( doSomething() ) );
           connect( ui.pushButton_quit, SIGNAL( clicked() ), this, SLOT( quit() ) );
           connect( ui.pushButton_about, SIGNAL( clicked() ), this, SLOT( about() ) );  
    }
    
       void simplecalc::doSomething()
    { 	
                double value1, value2;
     	char func;
    
      	value1 = ui.num1->value();        //error
    	//value1 = ui.num1->value();
     	value2 = ui.num2->value();
     	func = ui.sign->currentText();
     
      	if(func=='x')
     		ui.ans->settext() = value1 * value2;
     	else if(func=='รท')
     		ui.ans->settext(value1 / value2);
     	else if(func=='-')
     		ui.ans->settext(value1 - value2);
     	else if(func=='+') 
    		ui.ans->settext(value1 + value2);
     	//ans->settext() = value1 func value2; }
    
    void simplecalc::about()  
    {
         QMessageBox::information(this, tr("About\n\n"),
                        tr("This is a simple calculator program created by Josh Dye.\n")); }
    simplecalc.h
    Code:
    #ifndef SIMPLECALC_H
    #define SIMPLECALC_H
     
    #include "ui_SimpleCalc.h"
     
     
    class simplecalc : public QDialog
    {
        Q_OBJECT
     
    public:
        simplecalc(QWidget *parent = 0);
     
    public slots:
        void doSomething();
        void about();
    	
    };
    #endif
  • Laharl
    Recognized Expert Contributor
    • Sep 2007
    • 849

    #2
    There's nothing the second time because undefined references are only flagged once/function. The issue here is that you never say what 'ui' is. If it's supposed to be the namespace UI, you don't need it there, as long as you uncomment the using directive. If it's some kind of object, you need to create it.

    Comment

    • jpenguin
      New Member
      • Aug 2007
      • 41

      #3
      I got help on another forum

      :closed:

      Comment

      Working...