Hi,
i subclassed a QAbstractModel and subclassed the data function
which is declared as const.
However, i need to emit a signal from there and the compiler wont let me do that because of const...
What should i do?
Hi,
i subclassed a QAbstractModel and subclassed the data function
which is declared as const.
However, i need to emit a signal from there and the compiler wont let me do that because of const...
What should i do?
Simply you can't emit a signal inside a const method.
This is because a signal is transformed by moc into a call to QMetaObject::activate() with "this" as "sender" argument
Qt Code:
void MyClass::mySignal() { }To copy to clipboard, switch view to plain text mode
This method declare the first argument as "QObject* sender" and then it can't be const
A camel can go 14 days without drink,
I can't!!!
yes i know thats what the compiler tells me.
But i NEED this signal, what should i do? create another object on which i then can call the signal from the method?
redeclare it as a non-const in sub-class?
so how do i do that? just deleting "const" gives me errors related to qt.
of course it does... inheritance doesn't work that way.
what are you trying to do? there must be another way to do it.
Constness removed in derived class. Isn't that which you are trying to do?Qt Code:To copy to clipboard, switch view to plain text mode
Another way is const_cast on "this".
Code above compiles without errors for me. Am I wrong somewhere?
qtneuling, probably you're trying to do something different.
Yes, but QAbstractItemModel::data is pure virtual.
i need to emit this signal because my application needs to know when an item from my model was requested and which item it was
i created a new object with a method which emits the signal, and call that from the const function. This sucks but i dont see another way.
Bookmarks