Results 1 to 7 of 7

Thread: QList problem

  1. #1
    Join Date
    Feb 2006
    Posts
    12
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QList problem

    Hi everyone,
    I have created a list QList <AFile> list;
    Now, I know that in order to use the removeAll() method of the list, the operator==()
    must be implemented in the class AFile. I did implement it like this:
    Qt Code:
    1. bool AFile::operator==(AFile &file1) const
    2. {
    3. if(filePath!=file1.getFilePath()) //filepath is a QString
    4. return false;
    5. else
    6. return true;
    7. }
    To copy to clipboard, switch view to plain text mode 
    is there anything wrong with it?
    when i use the removeAll() the compiler shows the follow errors:

    Qt Code:
    1. usr/local/Trolltech/Qt-4.1.1/include/QtCore/qlist.h: In member function ‘int QList<T>::removeAll(const T&) [with T = AFile]’:
    2. video/AFileList.cpp:75: instantiated from here
    3. /usr/local/Trolltech/Qt-4.1.1/include/QtCore/qlist.h:549: error: no match for ‘operator==’ in ‘(n <unknown operator> ((QList<AFile>::Node*)((QList<AFile>*)this)->QList<AFile>::<anonymous>.QList<AFile>::<anonymous union>::p. QListData::at(i)))->QList<T>::Node::t [with T = AFile]() == t’
    4. video/AFile.h:22: note: candidates are: bool AFile::operator==(AFile&) const
    5. video/AFile.h:23: note: bool AFile::operator==(AFile*) const
    6. /usr/local/Trolltech/Qt-4.1.1/include/QtCore/qglobal.h:1266: note: bool operator==(QBool, bool)
    7. /usr/local/Trolltech/Qt-4.1.1/include/QtCore/qglobal.h:1267: note: bool operator==(bool, QBool)
    8. /usr/local/Trolltech/Qt-4.1.1/include/QtCore/qglobal.h:1268: note: bool operator==(QBool, QBool)
    9. /usr/local/Trolltech/Qt-4.1.1/include/QtCore/qchar.h:283: note: bool operator==(QChar, QChar)
    10. /usr/local/Trolltech/Qt-4.1.1/include/QtCore/qbytearray.h:421: note: bool operator==(const QByteArray&, const QByteArray&)
    11. /usr/local/Trolltech/Qt-4.1.1/include/QtCore/qbytearray.h:423: note: bool operator==(const QByteArray&, const char*)
    12. /usr/local/Trolltech/Qt-4.1.1/include/QtCore/qbytearray.h:425: note: bool operator==(const char*, const QByteArray&)
    13. /usr/local/Trolltech/Qt-4.1.1/include/QtCore/qstring.h:713: note: bool operator==(QString::Null, QString::Null)
    14. /usr/local/Trolltech/Qt-4.1.1/include/QtCore/qstring.h:714: note: bool operator==(QString::Null, const QString&)
    15. /usr/local/Trolltech/Qt-4.1.1/include/QtCore/qstring.h:715: note: bool operator==(const QString&, QString::Null)
    16. /usr/local/Trolltech/Qt-4.1.1/include/QtCore/qstring.h:733: note: bool operator==(const char*, const QString&)
    17. gmake[1]: *** [AFileList.o] Error 1
    18. gmake: *** [sub-src-make_default] Error 2
    19. *** Exited with status: 2 ***
    To copy to clipboard, switch view to plain text mode 

    thanks in advance!
    I Think therefore I Code...

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QList problem

    Try:
    Qt Code:
    1. bool AFile::operator==( const AFile& file1 ) const
    2. {
    3. return ( filePath == file1.getFilePath() );
    4. }
    To copy to clipboard, switch view to plain text mode 
    and make sure that getFilePath() is marked as const.

  3. #3
    Join Date
    Feb 2006
    Posts
    12
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QList problem

    Quote Originally Posted by jacek
    and make sure that getFilePath() is marked as const.
    I did that too , but the same compiler error, I really dont know whats going wrong.
    I Think therefore I Code...

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QList problem

    Have you declared that operator as public?

  5. #5
    Join Date
    Feb 2006
    Posts
    12
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QList problem

    Thanks jacek, I found the problem, it was really a stupid detail, messed up with the placement of const keyword, I didnt know well that there was a difference between:
    Qt Code:
    1. const void function();
    To copy to clipboard, switch view to plain text mode 
    and
    Qt Code:
    1. void function() const;
    To copy to clipboard, switch view to plain text mode 
    anyway thanks again for guiding me!
    I Think therefore I Code...

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QList problem

    Quote Originally Posted by acix
    I didnt know well that there was a difference between:
    Qt Code:
    1. const void function();
    To copy to clipboard, switch view to plain text mode 
    This marks the value returned as non-mutable (or "unmodifiable", "constant" -- you can't change its value).

    Qt Code:
    1. void function() const;
    To copy to clipboard, switch view to plain text mode 
    anyway thanks again for guiding me!
    This marks that the method doesn't modify the calling object ("this").

  7. The following user says thank you to wysota for this useful post:

    acix (29th April 2006)

  8. #7
    Join Date
    Feb 2006
    Posts
    12
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QList problem

    Thanks wysota for clarifying, I do get the difference now
    I Think therefore I Code...

Similar Threads

  1. QList, copy problems
    By Valheru in forum Qt Programming
    Replies: 4
    Last Post: 5th February 2010, 01:06
  2. QList problem
    By lvi in forum Qt Programming
    Replies: 3
    Last Post: 25th August 2008, 19:22
  3. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 10:12
  4. problem with QList
    By dreamer in forum Qt Programming
    Replies: 2
    Last Post: 12th May 2008, 14:08
  5. QList index out of range problem
    By MarkoSan in forum Qt Programming
    Replies: 2
    Last Post: 26th March 2008, 09:40

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.