Results 1 to 20 of 29

Thread: error: expected unqualified-id before numeric constant

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2008
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: error: expected unqualified-id before numeric constant

    Hi,

    I'm using Qt4.1, and I had the same problem and I have resolved it with an include and a replacement :
    #include <QKeyEvent> //that's very important
    (QEvent::Type)6 instead of QEvent::KeyPress

    example :
    KeyEvent* kevent = new QKeyEvent((QEvent::Type)6,buffer[0],(Qt::KeyboardModifiers)Qt::NoModifier,buffer,fals e,1);

    I hope it will help someone.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: error: expected unqualified-id before numeric constant

    You sure don't have to use such ugly C-style casts when you have the necessary include directive in place.

    Qt Code:
    1. #include <QKeyEvent>
    2. ...
    3. QKeyEvent* kevent = new QKeyEvent(QEvent::KeyPress,buffer[0],Qt::NoModifier,buffer,false,1);
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. #3
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: error: expected unqualified-id before numeric constant

    I don't understand why you don't use enum Qt::Key for second parameter in QKeyEvent ctor?

  4. #4

    Default Re: error: expected unqualified-id before numeric constant

    The problem is likely that you are including X.h which has

    Qt Code:
    1. // X.11.h
    2. ...
    3. ...
    4. #define KeyPress 2
    To copy to clipboard, switch view to plain text mode 

    So the preprocessor is converting this to...

    Qt Code:
    1. QKeyEvent* kevent = new QKeyEvent(QEvent::2,buffer[0],Qt::NoModifier,buffer,false,1);
    To copy to clipboard, switch view to plain text mode 

    Try adding

    Qt Code:
    1. #undef KeyPress // safe as long as you are not referencing KeyPress from X.h after this line
    2. QKeyEvent* kevent = new QKeyEvent(QEvent::KeyPress,buffer[0],Qt::NoModifier,buffer,false,1);
    To copy to clipboard, switch view to plain text mode 

    i.e. assuming that further down you won't be referring to KeyPress from X.h

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,328
    Thanks
    317
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: error: expected unqualified-id before numeric constant

    Why are you replying to a nearly 12 year old thread? Please check the date of the last post in a thread before bringing one back from the dead.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

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
  •  
Qt is a trademark of The Qt Company.