ports.h
Code: Alles auswählen
#ifndef _PORTS_H_
#define _PORTS_H_
#include <QObject>
#include <QMetaType>
/// ports on controller
class Ports:public QObject {
Q_OBJECT
// register Enum to the meta object system
Q_ENUMS(Ports::Type)
public:
enum Type {
AIN1=0,AIN2,AIN3,AIN4,
COUNTER1,COUNTER2,PWM1,PWM2,PWM3,PWM4
};
static QStringList list();
static QString toString(Ports::Type);
static Ports::Type fromString(const QString &);
private:
Ports();
};
#endif // _PORTS_H_
Code: Alles auswählen
#include "ports.h"
#include <QStringList>
QStringList Ports::list() {
return QStringList()<<"AIN1"
<<"AIN2"
<<"AIN3"
<<"AIN4"
<<"COUNTER1"
<<"COUNTER2"
<<"PWM1"
<<"PWM2"
<<"PWM3"
<<"PWM4";
}
QString Ports::toString(Ports::Type port){
return Ports::list().at(static_cast<int>(port));
}
Ports::Type Ports::fromString(const QString &port){
int index=Ports::list().indexOf(port);
if(index<0) {
qCritical(qPrintable(QString("Ports::fromString ")+
QString("unknown port")));
index=0;
}
return static_cast<Ports::Type>(index);
}
Code: Alles auswählen
#ifndef _PORTS_COMBO_BOX_H_
#define _PORTS_COMBO_BOX_H_
//#include "item_combo_box.h"
#include "ports.h"
#include <QComboBox>
class PortsComboBox:public QComboBox {
Q_OBJECT
Q_PROPERTY(Ports::Type port READ currentItem WRITE setCurrentItem)
Q_ENUMS(Ports::Type)
public:
explicit PortsComboBox(QWidget *parent=0);
void setCurrentItem(Ports::Type);
Ports::Type currentItem() const;
};
#endif // _PORTS_COMBO_BOX_H_
Code: Alles auswählen
#include "ports_combo_box.h"
PortsComboBox::PortsComboBox(QWidget *parent)
:QComboBox(parent)
{
addItems(Ports::list());
}
Ports::Type PortsComboBox::currentItem() const{
return Ports::fromString(currentText());
}
void PortsComboBox::setCurrentItem(Ports::Type port){
setCurrentIndex(static_cast<int>(port));
}
Warum wenn ich auf Property "port" zugreife bekomme ich die Fehlermeldung
Code: Alles auswählen
QMetaProperty::read: Unable to handle unregistered datatype 'Ports::Type' for property 'PortAssignmentSettingsBox::port'
P.S. Qt v. 4.4.0