Wrong function according to parameters is taken
Hi,
in my own model I have:
Code:
// BibtexGlobal::SearchFilter is an enum
And in an other class I call:
Code:
QModelIndex index
= sourceModel
()->index
(sourceRow,
0, sourceParent
);
QHash<BibtexGlobal
::SearchFilter,
QRegExp*>
::const_iterator i
= m_filter.
constBegin();
while (i != m_filter.constEnd())
{
qWarning() << sourceModel()->data(index, i.key());
++i;
}
But although i.key() is BibtexGlobal::SearchFilter the function data(const QModelIndex &index, int role) is called. Why? Is int and enum for the compiler the same?
Thanks
Re: Wrong function according to parameters is taken
A pure enum is a simple signed int, according to the C and C++ standard.
Unless you make a "typedef enum", both functions will be the same for your compiler.
Re: Wrong function according to parameters is taken
Quote:
Originally Posted by
Boron
Unless you make a "typedef enum", both functions will be the same for your compiler.
Proofed and "no" (leastwise in my case), but don't ask me why, because I'm not an information scientist. The problem was, that sourceModel() referred to a QAbstractItemModel* which hasn't a member with BibtexGlobal::SearchFilter. After an const_cast to my model all worked as expected. Even without a typedef the correct function is called.
Thanks anyway
Lykurg
Re: Wrong function according to parameters is taken
I wouldn't expect it to always work.
Re: Wrong function according to parameters is taken
Quote:
Originally Posted by
wysota
I wouldn't expect it to always work.
Depends on compiler/compiler version/plattform?
Currently I have changed the return value to a QString. Now - barring the original case - it should always work because the function has an other signature?
Thanks
Re: Wrong function according to parameters is taken
Quote:
Originally Posted by
Lykurg
Depends on compiler/compiler version/plattform?
Yeah, could be. I had a problem once when I had two variants of a method - one taking an int and one taking a string and when I was passing it const char *, it was always picking the int version because the conversion was "closer".