Results 1 to 8 of 8

Thread: Inhertiting QPtrList

  1. #1
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Red face Inhertiting QPtrList

    Hi Guys,
    I want to save the contents of the QPtrList to the Database.
    So Here is what i did

    Qt Code:
    1. //DataList.h
    2. template <typename T>
    3. class DataList : public QPtrList< T > {
    4.  
    5. public:
    6. DataList(){};
    7. virtual ~DataList(){};
    8. bool save();
    9. int lastError() const;
    10.  
    11. private:
    12. void setLastError( int iError );
    13.  
    14. private:
    15. int m_iLastError;
    16. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. //DataList.cpp
    2. template < typename T >
    3. DataList<T>::DataList()
    4. :m_iLastError( QueryResult::ErrorNotSet ) {}
    5.  
    6. template < typename T >
    7. bool DataList<T>::save() {
    8. DEBUG_WHERE();
    9. for ( T* pDataItem = first(); pDataItem; next() ) {
    10. bool bOperationFailed = true;
    11. if( pDataItem->indicator() == DataListItem::Inserted ) {
    12. bOperationFailed = pDataItem->insert();
    13.  
    14. } else if( pDataItem->indicator() == DataListItem::Updated ) {
    15. bOperationFailed = pDataItem->update();
    16.  
    17. } else if( pDataItem->indicator() == DataListItem::Deleted ) {
    18. bOperationFailed = pDataItem->remove();
    19. }
    20.  
    21. if( bOperationFailed ) {
    22. setLastError( pDataItem->lastError() );
    23. return false;
    24. }
    25. }
    26. return true;
    27. }
    To copy to clipboard, switch view to plain text mode 

    But g++ gives me the Following Error
    BusinessLogic/DataList.cpp: In member function `bool DataList<T>::save()':
    BusinessLogic/DataList.cpp:10: error: there are no arguments to `first' that depend on a template parameter, so a declaration of `first' must be available
    BusinessLogic/DataList.cpp:10: error: (if you use `-fpermissive', G++ will accept your code, but allowing theuse of an undeclared name is deprecated)
    BusinessLogic/DataList.cpp:10: error: there are no arguments to `next' that depend on a template parameter, so a declaration of `next' must be available

    Now where I am i going wrong
    Please Help
    We can't solve problems by using the same kind of thinking we used when we created them

  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: Inhertiting QPtrList

    Try:
    Qt Code:
    1. for ( T* pDataItem = QPtrList< T >::first(); pDataItem; pDataItem = QPtrList< T >::next() ) {
    2. // ...
    3. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Inhertiting QPtrList

    Thanks Jacek,
    But where did u refer this ?. Or which c++ book has this explained
    We can't solve problems by using the same kind of thinking we used when we created them

  4. #4
    Join Date
    Feb 2006
    Location
    Kirovohrad, Ukraine
    Posts
    72
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Inhertiting QPtrList

    Correct me, if I'm mistaken, but this code
    Quote Originally Posted by sunil.thaha
    Qt Code:
    1. //DataList.h
    2. template <typename T>
    3. class DataList : public QPtrList< T > {
    4.  
    5. public:
    6. DataList(){};
    7. // [Skip]
    8. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. //DataList.cpp
    2. template < typename T >
    3. DataList<T>::DataList()
    4. :m_iLastError( QueryResult::ErrorNotSet ) {}
    5. //[Skip]
    To copy to clipboard, switch view to plain text mode 
    should lead to link error, as Datalist<T>::Datalist() is implemented twice: both in header and in .cpp files. I suggest something like this:
    Qt Code:
    1. //DataList.h
    2. template <typename T>
    3. class DataList : public QPtrList< T > {
    4. public:
    5. DataList();
    6. // [Skip]
    7. };
    8.  
    9. //DataList.cpp
    10. template < typename T >
    11. DataList<T>::DataList() :
    12. QPtrList<T>(),
    13. m_iLastError( QueryResult::ErrorNotSet )
    14. {
    15. }
    16. //[Skip]
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Inhertiting QPtrList

    Quote Originally Posted by Cesar
    Correct me, if I'm mistaken, but this code
    those Errors were resolved

    Quote Originally Posted by Cesar
    Qt Code:
    1. //DataList.cpp
    2. template < typename T >
    3. DataList<T>::DataList() :
    4. QPtrList<T>(),
    5. m_iLastError( QueryResult::ErrorNotSet )
    6. {
    7. }
    8. //[Skip]
    To copy to clipboard, switch view to plain text mode 
    But do we need to call the Base Constructor Explicity
    Last edited by sunil.thaha; 8th February 2006 at 12:41.
    We can't solve problems by using the same kind of thinking we used when we created them

  6. #6
    Join Date
    Feb 2006
    Location
    Kirovohrad, Ukraine
    Posts
    72
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Inhertiting QPtrList

    Quote Originally Posted by sunil.thaha
    But do we need to call the Base Ponter Explicity
    Hm... Frankly saying, I'm not sure, anyway that won't hurt . I suppose the behaviour is compiler-dependent, so doing something explicitly should make the code more portable... I guess

  7. #7
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Inhertiting QPtrList

    No I don't think so. I have read that When a DErived object is created, the Derived Construtor will call the default constructor of the Base
    We can't solve problems by using the same kind of thinking we used when we created them

  8. #8
    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: Inhertiting QPtrList

    Quote Originally Posted by sunil.thaha
    But where did u refer this ?
    I was just using common sense.

Similar Threads

  1. Removing items from QPtrList efficiency issues
    By kalos80 in forum Qt Programming
    Replies: 1
    Last Post: 5th April 2007, 12:04
  2. QList usage in place QPtrList
    By darpan in forum Qt Programming
    Replies: 2
    Last Post: 25th October 2006, 15:41

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.