Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 3

Qt-interest Archive, December 2007
QHashIterator in a class definition


Message 1 in thread

Hello,

I have a class with a QHash and a QHashIterator. The PacketBuffer 
contains packets identified by a number. I've a procedure sendNextPacket 
  which picks the next packet from the PacketBuffer using itPacketBuffer.

--
 [ signature omitted ] 

Message 2 in thread

Reinder Feenstra wrote:
>Hello,
>
>I have a class with a QHash and a QHashIterator. The PacketBuffer
>contains packets identified by a number. I've a procedure sendNextPacket
>  which picks the next packet from the PacketBuffer using
> itPacketBuffer.
>
>--
>
>protected:
>   QHash<quint16,QByteArray> PacketBuffer;
>   QHashIterator<quint16,QByteArray> itPacketBuffer( PacketBuffer );
>
>When I want to compile i get the error:
>error: expected `;' before '(' token
>
>So I changed the code to:
>
>--
>
>protected:
>   QHash<quint16,QByteArray> PacketBuffer;
>   QHashIterator<quint16,QByteArray> itPacketBuffer;
>
>Then I get the error:
>error: no matching function for call to `QHashIterator<quint16,
>QByteArray>::QHashIterator()'
>
>--
>
>Can someone explain me what i'm going wrong?

You forgot to initialise the itPacketBuffer iterator in your constructor's 
intialisation list.

Please remember to re-initialise it every time the hash itself changes 
too.

-- 
 [ signature omitted ] 

Attachment: signature.asc
Description: This is a digitally signed message part.


Message 3 in thread

On Monday 17 December 2007 22:53:05 Reinder Feenstra wrote:
<SNIP />
> protected:
>    QHash<quint16,QByteArray> PacketBuffer;
>    QHashIterator<quint16,QByteArray> itPacketBuffer( PacketBuffer );
>
> When I want to compile i get the error:
> error: expected `;' before '(' token
>
> So I changed the code to:
>
> --
>
> protected:
>    QHash<quint16,QByteArray> PacketBuffer;
>    QHashIterator<quint16,QByteArray> itPacketBuffer;
>
> Then I get the error:
> error: no matching function for call to `QHashIterator<quint16,
> QByteArray>::QHashIterator()'
>
> --
>
> Can someone explain me what i'm going wrong?
>
> Greetings,
> Reinder
You're attempting to create an actual instance in your header.
Do it this way instead:

.h file
class MyClass: public Whatever{
...
protected:
QHash< quint16, QByteArray > PacketBuffer;
QHashIterator< quint16, QByteArray > itPacketBuffer;
};

.cpp file
MyClass::MyClass() 
   : Whatever()
    , itPacketBuffer(PacketBuffer) 
{
}


Happy coding,
Eric

>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body. List archive and information:
> http://lists.trolltech.com/qt-interest/


--
 [ signature omitted ] 

Message 4 in thread

Eric,

Thanks for the solution, now I understand what is was doing wrong.

Reinder

Eric Methorst wrote:
> On Monday 17 December 2007 22:53:05 Reinder Feenstra wrote:
> <SNIP />
>> protected:
>>    QHash<quint16,QByteArray> PacketBuffer;
>>    QHashIterator<quint16,QByteArray> itPacketBuffer( PacketBuffer );
>>
>> When I want to compile i get the error:
>> error: expected `;' before '(' token
>>
>> So I changed the code to:
>>
>> --
>>
>> protected:
>>    QHash<quint16,QByteArray> PacketBuffer;
>>    QHashIterator<quint16,QByteArray> itPacketBuffer;
>>
>> Then I get the error:
>> error: no matching function for call to `QHashIterator<quint16,
>> QByteArray>::QHashIterator()'
>>
>> --
>>
>> Can someone explain me what i'm going wrong?
>>
>> Greetings,
>> Reinder
> You're attempting to create an actual instance in your header.
> Do it this way instead:
> 
> .h file
> class MyClass: public Whatever{
> ...
> protected:
> QHash< quint16, QByteArray > PacketBuffer;
> QHashIterator< quint16, QByteArray > itPacketBuffer;
> };
> 
> .cpp file
> MyClass::MyClass() 
>    : Whatever()
>     , itPacketBuffer(PacketBuffer) 
> {
> }
> 
> 
> Happy coding,
> Eric
> 
>> --
>> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
>> "unsubscribe" in the subject or the body. List archive and information:
>> http://lists.trolltech.com/qt-interest/
> 
> 
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/

--
 [ signature omitted ]