TomJoad
15th March 2011, 20:47
I need help as I have no idea what I could be doing wrong. I have been trying to follow the Calc Form Example (http://doc.trolltech.com/4.7/designer-calculatorform.html) and can't for the life of me figure out what I am doing wrong.
Here are the error codes that are thrown when trying to compile:
..\test\widget.cpp: In member function 'void Widget::on_def_valueChanged(int)':
..\test\widget.cpp:17: error: request for member 'total' in '((Widget*)this)->Widget::ui', which is of non-class type 'Ui::Widget*'
..\test\widget.cpp:17: error: request for member 'soc' in '((Widget*)this)->Widget::ui', which is of non-class type 'Ui::Widget*'
Here is widget.cpp:
#include "widget.h"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
}
Widget::~Widget()
{
delete ui;
}
void Widget::on_def_valueChanged(int value)
{
ui.total->setText(QString::number(value * 2 + ui.soc->value()));
}
main.cpp:
#include <QtGui/QApplication>
#include "widget.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
widget.h:
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include "ui_widget.h"
namespace Ui {
class Widget;
}
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
private slots:
void on_def_valueChanged(int value);
private:
Ui::Widget *ui;
};
#endif // WIDGET_H
and test.pro
#-------------------------------------------------
#
# Project created by QtCreator 2011-03-15T16:01:49
#
#-------------------------------------------------
QT += core gui
TARGET = test
TEMPLATE = app
SOURCES += main.cpp\
widget.cpp
HEADERS += widget.h
FORMS += widget.ui
"def" and "soc" are qspinboxs, and "total" is a qlabel.
This should be simple, right? I'm sitting here banging my head against the wall. :crying:
Here are the error codes that are thrown when trying to compile:
..\test\widget.cpp: In member function 'void Widget::on_def_valueChanged(int)':
..\test\widget.cpp:17: error: request for member 'total' in '((Widget*)this)->Widget::ui', which is of non-class type 'Ui::Widget*'
..\test\widget.cpp:17: error: request for member 'soc' in '((Widget*)this)->Widget::ui', which is of non-class type 'Ui::Widget*'
Here is widget.cpp:
#include "widget.h"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
}
Widget::~Widget()
{
delete ui;
}
void Widget::on_def_valueChanged(int value)
{
ui.total->setText(QString::number(value * 2 + ui.soc->value()));
}
main.cpp:
#include <QtGui/QApplication>
#include "widget.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
widget.h:
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include "ui_widget.h"
namespace Ui {
class Widget;
}
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
private slots:
void on_def_valueChanged(int value);
private:
Ui::Widget *ui;
};
#endif // WIDGET_H
and test.pro
#-------------------------------------------------
#
# Project created by QtCreator 2011-03-15T16:01:49
#
#-------------------------------------------------
QT += core gui
TARGET = test
TEMPLATE = app
SOURCES += main.cpp\
widget.cpp
HEADERS += widget.h
FORMS += widget.ui
"def" and "soc" are qspinboxs, and "total" is a qlabel.
This should be simple, right? I'm sitting here banging my head against the wall. :crying: