calculator.h聯盟和QT-Formfileds
#ifndef CALCULATORFORM_H
#define CALCULATORFORM_H
#include "ui_calculatorform.h"
class CalculatorForm : public QWidget, private Ui::CalculatorForm
{
Q_OBJECT
public:
CalculatorForm(QWidget *parent = 0);
private slots:
void on_inputSpinBox1_valueChanged(unsigned short value);
void on_inputSpinBox2_valueChanged(unsigned short value);
};
#endif
我的程序:
class my
{
public:
union urgl
{
unsigned short a[2];
float f;
};
urgl obj;
};
void CalculatorForm::on_inputSpinBox1_valueChanged(unsigned short value) {
my v;
v.obj.a[0]=inputSpinBox1->value;
v.obj.a[1]=inputSpinBo2->value;
outputWidget->setText(QString::number(inputSpinBox2->v.obj.f()));
}
void CalculatorForm::on_inputSpinBox2_valueChanged(unsigned short value)
{
my v;
v.obj.a[0]=inputSpinBox1->value;
v.obj.a[1]=inputSpinBox2->value;
outputWidget->setText(QString::number(inputSpinBox1->v.obj.f()));
}
我得到一些錯誤:
'QSpinBox::value' from type 'int (QSpinBox::)() const' to type 'short unsigned int'
v.obj.a[0]=inputSpinBox1->value;
^
..\multipleinheritance\calculatorform.cpp:74:16: error: 'inputSpinBo2' was not declared in this scope
v.obj.a[1]=inputSpinBo2->value;
^
**strong text**..\multipleinheritance\calculatorform.cpp:75:59: error: 'class QSpinBox' has no member named 'v'
outputWidget->setText(QString::number(inputSpinBox2->v.obj.f()));
^
..\multipleinheritance\calculatorform.cpp: At global scope:
..\multipleinheritance\calculatorform.cpp:71:67: warning: unused parameter 'value' [-Wunused-parameter]
void CalculatorForm::on_inputSpinBox1_valueChanged(unsigned short value)
^
..\multipleinheritance\calculatorform.cpp: In member function 'void CalculatorForm::on_inputSpinBox2_valueChanged(short unsigned int)':
..\multipleinheritance\calculatorform.cpp:83:15: error: cannot convert 'QSpinBox::value' from type 'int (QSpinBox::)() const' to type 'short unsigned int'
v.obj.a[0]=inputSpinBox1->value;
^
..\multipleinheritance\calculatorform.cpp:84:15: error: cannot convert 'QSpinBox::value' from type 'int (QSpinBox::)() const' to type 'short unsigned int'
v.obj.a[1]=inputSpinBox2->value;
^
..\multipleinheritance\calculatorform.cpp:86:59: error: 'class QSpinBox' has no member named 'v'
outputWidget->setText(QString::number(inputSpinBox1->v.obj.f()));
^
..\multipleinheritance\calculatorform.cpp: At global scope:
..\multipleinheritance\calculatorform.cpp:80:67: warning: unused parameter 'value' [-Wunused-parametervoid
CalculatorForm::on_inputSpinBox2_valueChanged(unsigned short value)
^
Makefile.Debug:592: recipe for target 'debug/calculatorform.o' failed
我在哪裏可以稱之爲 「我的」 類所以它可以被其他類訪問? 如何顯示輸出文本字段中的浮點值? 我正在使用Qt Designer 5.5
對不起,錯別字在這裏是題外話。仔細閱讀代碼,並確保沒有錯別字。到目前爲止,我看到的只是錯別字,錯別字,錯別字。瞭解代碼的含義。 –