# Not able to get the Clue

This topic is 3344 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Here goes my code:
class PHPConstructIdentity::Impl{
private:
struct InternalImpl{
QStringList userClass;
QStringList systemClass;
QStringList phpClass;

QStringList userFunction;
QStringList systemFunction;
QStringList phpFunction;

QStringList userMacro;
QStringList systemMacro;
QStringList phpMacro;
};
InternalImpl* pImpl;
private:
class ConstructPointer{
private:
Construct c;
ConstructType t;
public:
ConstructPointer(Construct cns, ConstructType cnsT):c(cns), t(cnsT){}
bool operator==(const ConstructPointer& cnsPt) const{
return (cnsPt.c == c && cnsPt.t == t);
};
};
private:
QHash<ConstructPointer, QStringList*> constructList;
public:
Impl(){
constructList[ConstructPointer(Class, User)] = &pImpl->userClass;
constructList[ConstructPointer(Class, System)] = &pImpl->systemClass;
constructList[ConstructPointer(Class, PHP)] = &pImpl->phpClass;
constructList[ConstructPointer(Function, User)] = &pImpl->userFunction;
constructList[ConstructPointer(Function, System)] = &pImpl->systemFunction;
constructList[ConstructPointer(Function, PHP)] = &pImpl->phpFunction;
constructList[ConstructPointer(Macro, User)] = &pImpl->userMacro;
constructList[ConstructPointer(Macro, System)] = &pImpl->systemMacro;
constructList[ConstructPointer(Macro, PHP)] = &pImpl->phpMacro;
}
QStringList& construct(Construct cns, ConstructType cnsTp) const{
return *constructList[ConstructPointer(cns, cnsTp)];
}
};


and the following error is being fired:
compiling phpconstructidentity.cpp (g++)
/usr/local/Trolltech/Qt-4.4.0/include/QtCore/qhash.h:725: instantiated from 'T& QHash<Key, T>::operator[](const Key&) [with Key = PHPConstructIdentity::Impl::ConstructPointer, T = QStringList*]'
phpconstructidentity.cpp:38: instantiated from here
/usr/local/Trolltech/Qt-4.4.0/include/QtCore/qhash.h:860: error: no matching function for call to 'qHash(const PHPConstructIdentity::Impl::ConstructPointer&)'
/usr/local/Trolltech/Qt-4.4.0/include/QtCore/qhash.h:65: note: candidates are: uint qHash(char)
/usr/local/Trolltech/Qt-4.4.0/include/QtCore/qhash.h:66: note: uint qHash(uchar)
/usr/local/Trolltech/Qt-4.4.0/include/QtCore/qhash.h:67: note: uint qHash(signed char)
/usr/local/Trolltech/Qt-4.4.0/include/QtCore/qhash.h:68: note: uint qHash(ushort)
/usr/local/Trolltech/Qt-4.4.0/include/QtCore/qhash.h:69: note: uint qHash(short int)
/usr/local/Trolltech/Qt-4.4.0/include/QtCore/qhash.h:70: note: uint qHash(uint)
/usr/local/Trolltech/Qt-4.4.0/include/QtCore/qhash.h:71: note: uint qHash(int)
/usr/local/Trolltech/Qt-4.4.0/include/QtCore/qhash.h:72: note: uint qHash(ulong)
/usr/local/Trolltech/Qt-4.4.0/include/QtCore/qhash.h:80: note: uint qHash(long int)
/usr/local/Trolltech/Qt-4.4.0/include/QtCore/qhash.h:81: note: uint qHash(quint64)
/usr/local/Trolltech/Qt-4.4.0/include/QtCore/qhash.h:89: note: uint qHash(qint64)
/usr/local/Trolltech/Qt-4.4.0/include/QtCore/qhash.h:90: note: uint qHash(QChar)
/usr/local/Trolltech/Qt-4.4.0/include/QtCore/qhash.h:91: note: uint qHash(const QByteArray&)
/usr/local/Trolltech/Qt-4.4.0/include/QtCore/qhash.h:92: note: uint qHash(const QString&)
/usr/local/Trolltech/Qt-4.4.0/include/QtCore/qhash.h:93: note: uint qHash(const QStringRef&)
/usr/local/Trolltech/Qt-4.4.0/include/QtCore/qhash.h:94: note: uint qHash(const QBitArray&)
*** Exited with status: 2 ***


##### Share on other sites
Not clear where's the error is coming from, but it seems like you don't have something set up right to use a QHash. It's possible QHash may only compile correctly on classes with a default constructor.

A separate question, though, why are you using Qt containers instead of the STL containers? When I've used Qt, I recall not being particularly in love with their containers. I understand that they created them for embedded platforms that might not have good STL implementations, but they definitely reinvented the wheel.

##### Share on other sites
When you use a third party library, it is absolutely essential that you read the documentation. You can't just write some code and expect it to work if you don't know what you're doing. You should also try to read the documentation before coming here to ask a question—people tend to point and laugh when the answer you're looking for can be found in 10 seconds by googling "qHash", without even any knowledge of what qHash is.

Quote:
 QHash class referenceThe key type of a QHash must provide operator==() and a global qHash(Key) function.[...]The qHash() function computes a numeric value based on a key. It can use any algorithm imaginable, as long as it always returns the same value if given the same argument. In other words, if e1 == e2, then qHash(e1) == qHash(e2) must hold as well. However, to obtain good performance, the qHash() function should attempt to return different hash values for different keys to the largest extent possible.

##### Share on other sites
Ya I think default Constructor is teh point.
Quote:
 Original post by RydinareA separate question, though, why are you using Qt containers instead of the STL containers? When I've used Qt, I recall not being particularly in love with their containers. I understand that they created them for embedded platforms that might not have good STL implementations, but they definitely reinvented the wheel.
I 100% agree with you.I am really suffering with it.still I am not able to get a clear idea where is the function like make_pair() in Qt. However I am not much also interested (and not much experienced with Qt Containers too) to Qt's Containers. However This time as I am coding some Qt Application I thought to do it with QHash or QMap.
However I can do the with STL.
Quote:
Original post by ToohrVyk
When you use a third party library, it is absolutely essential that you read the documentation. You can't just write some code and expect it to work if you don't know what you're doing. You should also try to read the documentation before coming here to ask a question—people tend to point and laugh when the answer you're looking for can be found in 10 seconds by googling "qHash", without even any knowledge of what qHash is.

Quote:
 QHash class referenceThe key type of a QHash must provide operator==() and a global qHash(Key) function.[...]The qHash() function computes a numeric value based on a key. It can use any algorithm imaginable, as long as it always returns the same value if given the same argument. In other words, if e1 == e2, then qHash(e1) == qHash(e2) must hold as well. However, to obtain good performance, the qHash() function should attempt to return different hash values for different keys to the largest extent possible.

bool operator==(const ConstructPointer& cnsPt) const{  return (cnsPt.c == c && cnsPt.t == t);};

##### Share on other sites
Quote:
Original post by nlbs
Ya I think default Constructor is teh point.
Quote:
 Original post by RydinareA separate question, though, why are you using Qt containers instead of the STL containers? When I've used Qt, I recall not being particularly in love with their containers. I understand that they created them for embedded platforms that might not have good STL implementations, but they definitely reinvented the wheel.
I 100% agree with you.I am really suffering with it.still I am not able to get a clear idea where is the function like make_pair() in Qt. However I am not much also interested (and not much experienced with Qt Containers too) to Qt's Containers. However This time as I am coding some Qt Application I thought to do it with QHash or QMap.
However I can do the with STL.
Quote:
Original post by ToohrVyk
When you use a third party library, it is absolutely essential that you read the documentation. You can't just write some code and expect it to work if you don't know what you're doing. You should also try to read the documentation before coming here to ask a question—people tend to point and laugh when the answer you're looking for can be found in 10 seconds by googling "qHash", without even any knowledge of what qHash is.

Quote:
 QHash class referenceThe key type of a QHash must provide operator==() and a global qHash(Key) function.[...]The qHash() function computes a numeric value based on a key. It can use any algorithm imaginable, as long as it always returns the same value if given the same argument. In other words, if e1 == e2, then qHash(e1) == qHash(e2) must hold as well. However, to obtain good performance, the qHash() function should attempt to return different hash values for different keys to the largest extent possible.

bool operator==(const ConstructPointer& cnsPt) const{  return (cnsPt.c == c && cnsPt.t == t);};

As it says, you're missing the global qHash() key function for that type.

##### Share on other sites
Quote:
 Original post by nlbsPlease take a look at the code. I already have an operator=() overload.bool operator==(const ConstructPointer& cnsPt) const{ return (cnsPt.c == c && cnsPt.t == t);};

You seem to have missed a few "details" in my post. I can understand that you would have just skipped them, because they were well-hidden and most of the text did not discuss these details at all.

Just so you don't miss them again, I have taken the liberty of highlighting them in big bold red text:

Quote:
 QHash class referenceThe key type of a QHash must provide operator==() and a global qHash(Key) function.[...]The qHash() function computes a numeric value based on a key. It can use any algorithm imaginable, as long as it always returns the same value if given the same argument. In other words, if e1 == e2, then qHash(e1) == qHash(e2) must hold as well. However, to obtain good performance, the qHash() function should attempt to return different hash values for different keys to the largest extent possible.