Results 1 to 5 of 5

Thread: QList err : expected primary-expression before ‘)’ token

  1. #1
    Join Date
    Dec 2010
    Location
    UK
    Posts
    9
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QList err : expected primary-expression before ‘)’ token

    Hi all
    Please for support and help
    Thanks in advance!
    Qt Code:
    1. my list in .h file
    2.  
    3. QList < FilmDoc > * pDocList;
    4.  
    5. void FilmApp::openDocumentFile (const char *file)
    6. {
    7. statusBar ()->message (tr ("Opening file..."));
    8.  
    9. QList <FilmDoc> doc = *pDocList;
    10.  
    11. // if this might help function has to check if file is already opened
    12. // and if yes then setFocus to opened view
    13. for ( int i = 0; i < doc.size (); ++i ) {
    14. if ( doc.contains ( doc& ) == file ){// this line generate err
    15.  
    16. FilmView * view = doc->firstView ();
    17. view->setFocus ();
    18. return;
    19. }
    20. }
    21. ...
    22. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QList err : expected primary-expression before ‘)’ token

    doc.contains ( doc& ) makes no sense.
    you probably want:
    Qt Code:
    1. if(doc.at(i) == file){
    2. ...
    3. }
    To copy to clipboard, switch view to plain text mode 
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Dec 2010
    Location
    UK
    Posts
    9
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QList err : expected primary-expression before ‘)’ token

    thx but this code is generating msg;

    "error: no match for ‘operator==’ in ‘doc.QList<T>::at [with T = FilmDoc](i) == file’
    candidates are: bool operator==(QBool, bool)
    ...
    and much more of this
    "

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QList err : expected primary-expression before ‘)’ token

    it means that FilmDoc has no '==' operator.
    You will have to compare some property of FilmDoc to make sure you have the one you need.
    If there is no such property, you will have to implement the '==' operator.
    But you probably can get away with storing pointers, which you can compare, and they are unique per item.
    QList<FilmDoc *> myList;
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QList err : expected primary-expression before ‘)’ token

    Qt Code:
    1. if ( doc.contains ( doc& ) == file ){// this line generate err
    To copy to clipboard, switch view to plain text mode 

    This line makes no sense, as someone else pointed out. Even if you got the syntax right, it still makes no sense.

    Assuming what you want is

    Qt Code:
    1. if( doc.at(i) == file )
    To copy to clipboard, switch view to plain text mode 

    then what that line says is to compare a "FilmDoc" object (that's what is getting retrieved from the QList using the at() method) to a char * string. If your FilmDoc class doesn't have a

    Qt Code:
    1. bool operator==( const char * ) const;
    To copy to clipboard, switch view to plain text mode 

    method, then this is what is generating your compile error.

    You probably want code that looks something like this:

    Qt Code:
    1. void FilmApp::openDocumentFile (const char *file)
    2. {
    3. statusBar ()->message (tr ("Opening file..."));
    4.  
    5. QList <FilmDoc> doc = *pDocList;
    6.  
    7. // if this might help function has to check if file is already opened
    8. // and if yes then setFocus to opened view
    9. for ( int i = 0; i < doc.size (); ++i ) {
    10. const FileDoc & fileDoc = doc.at( i );
    11. if (fileDoc.name() == file ) {
    12. // But now this line will generate an error, because QList<T> doesn't have a "firstView()" method.
    13. // You probably mean: FilmView * view = fileDoc.firstView() instead
    14. FilmView * view = doc->firstView ();
    15. view->setFocus ();
    16. return;
    17. }
    18. }
    19. ...
    20. }
    To copy to clipboard, switch view to plain text mode 


    Added after 7 minutes:


    Sorry, I meant "FilmDoc", not "FileDoc" in line 10. Got confused comparing films and files.
    Last edited by d_stranz; 3rd January 2011 at 01:16.

Similar Threads

  1. expected `)' before '*' token
    By vinod sharma in forum Qt Programming
    Replies: 3
    Last Post: 15th March 2010, 07:57
  2. Expected class-name before '{' token
    By imagiro1 in forum Newbie
    Replies: 16
    Last Post: 16th June 2009, 11:37
  3. error: expected class-name before '{' token
    By Aresti in forum Qt Programming
    Replies: 1
    Last Post: 12th November 2008, 20:00
  4. Replies: 3
    Last Post: 10th November 2008, 16:14
  5. expected initializer before »)« token
    By Holy in forum Qt Programming
    Replies: 2
    Last Post: 24th May 2008, 16:24

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.