Results 1 to 6 of 6

Thread: error: expected primary-expression before '=' token

  1. #1
    Join Date
    May 2011
    Location
    Mumbai, India
    Posts
    22
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default error: expected primary-expression before '=' token

    (void)new Q3CheckListItem (ui->view,*it, Q3CheckListItem::Type = Q3CheckListItem::CheckBox );

    got this error,
    error: expected primary-expression before '=' token

    plz help...

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: error: expected primary-expression before '=' token

    You need to assign the result of the code shown to something.

  3. #3
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: error: expected primary-expression before '=' token

    you can't assign something to an enum...

    Qt Code:
    1. Q3CheckListItem::Type = Q3CheckListItem::CheckBox
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: error: expected primary-expression before '=' token

    Do you mean
    Qt Code:
    1. (void)new Q3CheckListItem (ui->view,*it, Q3CheckListItem::CheckBox );
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Apr 2011
    Posts
    124
    Thanks
    1
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60

    Default Re: error: expected primary-expression before '=' token

    You're confusing how you prototype a method with how you actually code it for a call. In the prototype description something like "Q3CheckListItem::Type = Q3CheckListItem::CheckBox" means that that parameter is optional and will take the value "Q3CheckListItem::CheckBox" if you omit it in the call. If you want a different value you'd simply code the value. Eg:

    "... someParm, Q3CheckListItem::ShoeBox)"

    for the case where one of the enum values from Q3CheckListItem is expected.

    And I'm not sure where you got the "(void)".

    (And, of course, you shouldn't be using the Q3 stuff.)

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: error: expected primary-expression before '=' token

    The (void) explicitly discards the returned pointer from the call to new, makes it obvious you intended to discard the return value, and avoids a warning from compilers that issue one when you ignore a return. OTOH, if it weren't for QObject's memory management this construct would create a memory leak.

Similar Threads

  1. Replies: 4
    Last Post: 3rd January 2011, 01:16
  2. Replies: 13
    Last Post: 19th May 2010, 05:34
  3. Replies: 3
    Last Post: 10th November 2008, 16:14
  4. Replies: 4
    Last Post: 22nd February 2008, 19:08
  5. Replies: 2
    Last Post: 30th January 2008, 20:06

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.