cszawisza
15th April 2014, 11:14
Hi!
My application uses nanopb protocol to communicate with my µC application via TCP/IP, simplified structure of my messages is as follows
message MsgText{
enum Type {
debug = 0; // info messages
warning = 1; // something go wrong
fatal = 2; // something goes very wrong
}
required int32 ID = 1 [default = 0xff];
required Type type = 2;
required string txt = 3;
}
message MsgMeasurements{
required int32 ID = 1 [default = 0x02];
required int32 meassurement1 = 2;
required int32 meassurement2 = 3;
}
In my application I create a class named MyProtocol and there implement a method that reads data from TCP socket and emits signals for recived fields in messages
class MyProtocol : public QObject
Q_OBJECT
slots:
void readData();
signals:
void dataRecived( int ); // all recived data
void messagesRecived( int ); //all recived messages
/// text messages
void dbgMsgReceived( QString txt) ;
void warnMsgReceived( QString msg );
vaoi infoMsgReceived( QString txt );
// measurements
void measure1Received( int );
void measure2Received( int );
}
so in my mainwindow class i can just connect a dataRecived signal to a slot and everything is fine, the same with rest of signals. But now I want to move different messages types to different classes, and if possible provide a way not to change my mainwindow class. So i thought that this structure will by OK
class MyText : public QObject {
Q_OBJECT
signals:
/// text messages
void dbgMsgReceived( QString txt) ;
void warnMsgReceived( QString msg );
vaoi infoMsgReceived( QString txt );
}
class MyMeasurements : public QObject
{
Q_OBJECT
signals:
// measurements
void measure1Received( int );
void measure2Received( int );
}
class MyProtocol : public MyMeasurements, MyText
Q_OBJECT
void readData();
signals:
void dataRecived( int ); // all recived data
void messagesRecived( int ); //all recived messages
}
But unfortunately I can't inherit QObject from meany sources... I know that without inherit I can just create a object of MyText and MyMeasurements in MyProtocol and then connect signals from them to signals in MyProtocol, but it seams to by not a good idea.
What are a typical approaches to such problems? Can somebody tell me what hierarchy I should chose?
My application uses nanopb protocol to communicate with my µC application via TCP/IP, simplified structure of my messages is as follows
message MsgText{
enum Type {
debug = 0; // info messages
warning = 1; // something go wrong
fatal = 2; // something goes very wrong
}
required int32 ID = 1 [default = 0xff];
required Type type = 2;
required string txt = 3;
}
message MsgMeasurements{
required int32 ID = 1 [default = 0x02];
required int32 meassurement1 = 2;
required int32 meassurement2 = 3;
}
In my application I create a class named MyProtocol and there implement a method that reads data from TCP socket and emits signals for recived fields in messages
class MyProtocol : public QObject
Q_OBJECT
slots:
void readData();
signals:
void dataRecived( int ); // all recived data
void messagesRecived( int ); //all recived messages
/// text messages
void dbgMsgReceived( QString txt) ;
void warnMsgReceived( QString msg );
vaoi infoMsgReceived( QString txt );
// measurements
void measure1Received( int );
void measure2Received( int );
}
so in my mainwindow class i can just connect a dataRecived signal to a slot and everything is fine, the same with rest of signals. But now I want to move different messages types to different classes, and if possible provide a way not to change my mainwindow class. So i thought that this structure will by OK
class MyText : public QObject {
Q_OBJECT
signals:
/// text messages
void dbgMsgReceived( QString txt) ;
void warnMsgReceived( QString msg );
vaoi infoMsgReceived( QString txt );
}
class MyMeasurements : public QObject
{
Q_OBJECT
signals:
// measurements
void measure1Received( int );
void measure2Received( int );
}
class MyProtocol : public MyMeasurements, MyText
Q_OBJECT
void readData();
signals:
void dataRecived( int ); // all recived data
void messagesRecived( int ); //all recived messages
}
But unfortunately I can't inherit QObject from meany sources... I know that without inherit I can just create a object of MyText and MyMeasurements in MyProtocol and then connect signals from them to signals in MyProtocol, but it seams to by not a good idea.
What are a typical approaches to such problems? Can somebody tell me what hierarchy I should chose?