Solved QT how to take enum object inside the QList and print accordingly ?
-
@raven-worx this on my .h file
namespace DC { enum EnumType { FileMetaInformationGroupLength = 0x00020000, FileMetaInformationVersion = 0x00020001, MediaStorageSOPClassUID = 0x00020002, MediaStorageSOPInstanceUID = 0x00020003 .......... 5000 }; Q_ENUM(EnumType); }
and I am reading the file staticlly here in .cpp file
QString readFile::SetTagNames(QStandardItemModel *model) { char *DisplayTags[] = { " FileMetaInformationGroupLength ", "FileMetaInformationVersion", "MediaStorageSOPClassUID" , "MediaStorageSOPInstanceUID", "ImplementationClassUID"}; for (int i = 0; i < total ; i++) { model->setData(model->index(i, 0), DisplayTags[i]); } return QString(); }
reading respective date through
model->setData(model->index(0, 1), pMetaData->GetAttributeValue(DC::FileMetaInformationGroupLength ).GetCharData()); model->setData(model->index(1, 1), pMetaData->GetAttributeValue(DC::FileMetaInformationVersion).GetCharData()); model->setData(model->index(2, 1), pMetaData->GetAttributeValue(DC::MediaStorageSOPClassUID).GetCharData()); model->setData(model->index(3, 1), pMetaData->GetAttributeValue(DC::MediaStorageSOPInstanceUID).GetCharData());
-
@amarism said in QT how to take enum object inside the QList and print accordingly ?:
namespace DC
{
enum EnumType {
FileMetaInformationGroupLength = 0x00020000,
FileMetaInformationVersion = 0x00020001,
MediaStorageSOPClassUID = 0x00020002,
MediaStorageSOPInstanceUID = 0x00020003
.......... 5000
};
Q_ENUM(EnumType);
}as i mentioned you should use
Q_NAMESPACE
!namespace DC { Q_NAMESPACE ... }
-
@raven-worx i will take one example in QT.
enum data{ a,b,c,d }; Q_ENUM(data)
and .cpp file
QMetaEnum e = QMetaEnum::fromType<data>(); for(int i=0;i<=d;i++){ qDebug()<<e.valueToKey(data::a); }
It will print only d(4times). But I want to print a,b,c,d
-
@amarism said in QT how to take enum object inside the QList and print accordingly ?:
qDebug()<<e.valueToKey(data::a);
it rather prints 4 times the value of
data::a
since you tell it to do so:qDebug()<<e.valueToKey(data::a);
-
for(int i=0;i<=d;i++){ qDebug()<<e.valueToKey(data::a); }
Like @raven-worx says; you probably want to access that
i
loop counter inside the loop, don't you? :) -
This post is deleted! -
for(int i=0;i<=d;i++){ qDebug()<<e.valueToKey(static_cast<data>(i)); }
-
@amarism said in QT how to take enum object inside the QList and print accordingly ?:
i tried to take i inside the loop but its show error " 'i': illegal qualified name in member declaration "
QMetaEnum::valueToKey() takes an int parameter, so i don't see why the following shouldn't work.
for(int i=0;i<=d;i++){ qDebug() << e.valueToKey(i); }
-
@raven-worx ya its working , Thanks a lots
-
@J.Hilk Without QT, Can I do the same thing(by using the normal C++ method like a 2-D array) ??