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
    Feb 2007
    Posts
    32
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

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

    No that is not the problem.

  2. #2
    Join Date
    Feb 2007
    Posts
    32
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

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

    Hi all,
    Was my question absurd ?
    I am unable to find the clue for this, this is a big issue in my application. The same was runnig fine on Windows but unable to compile on LINUX

  3. #3
    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: error: expected unqualified-id before numeric constant

    Could we see the exact and complete (including file name and line numbers) error message?

  4. #4
    Join Date
    Feb 2007
    Posts
    32
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

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

    MDIWindow2D.cxx:1665: error: expected unqualified-id before numeric constant

  5. #5
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

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

    Can you post the entire code section?
    Let's say lines 1660 - 1680?

  6. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

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

    Hey, I think I found something.
    Take a look at this article: http://braincore.blogspot.com/2005_11_01_archive.html

    I'm talking about:
    cpp: preprocessing can bite

    Ready for a new type of post? cpp? What is it? Well, KDE and Qt are primarily written in C++. I do have experience in that language. And sometimes a question pops up that begs for an answer.So here goes.
    qnamespace.h:833: error: expected identifier before numeric constant
    qnamespace.h:833: error: expected unqualified-id before numeric constant
    Say what? Pretty cryptic error message. So, what's happening in qnamespace.h at that particular line?// documented in qcursor.cpp
    enum CursorShape {
    ArrowCursor,
    UpArrowCursor,
    CrossCursor,
    ....
    Line 833 is the one that starts with the enum. At this point, the problem still evaded me. So, let's have a look at the source that is compiled. It contained among others these lines#include "config.h" // HAVE_LIBXSS

    #ifdef HAVE_LIBXSS // Idle detection.
    #include <X11/Xlib.h>
    #include <X11/Xutil.h>
    #include <X11/extensions/scrnsaver.h>
    #include <fixx11h.h>
    #endif // HAVE_LIBXSS

    #include <kapplication.h>Well, after undefining HAVE_LIBXSS after the inclusion of the config header, the error went away. Hmmm. Could it be that somewhere in the X11 headers the name CursorShape is used? So, fire up a konsole, navigate to the directory holding the relevant headers and execute find . -type f | xargs grep CursorShapewhich turns up#define CursorShape 0 /* largest size that can be displayed */Aha! The plot thickens. Because when this is preprocessed before the enum in qnamespace.h, that particular enum will come out like enum 0 {... which is obviously not a good thing.This is a classic case of how preprocessing can bite a programmer and yield an error message that seems totally unrelated to what is actually wrong. So, the solution is to change the order in which headers are included. In this particular case that meant moving the X11 headers to the end of the #include stanzas.
    Now, before you start falling all over me that this is not a solution, yes, I know it is not a proper solution. I'm aware of the fact that if one uses CursorShape after having included the X11 headers, I will get exactly the same trouble. In this case, that didn't happen. And for now, the code works.
    Update -- I should have known. No, this piece is not about how to fix it, it is about how preprocessing can bite you. And yes - #undef CursorShape would be an alternate approach but equally bad. And no - including fixx11.h didn't.
    I'm not saying that you have exactly the same problem but it's worth investigating further.

    Judging from what I've read about this error, it appears because there is an already processed macro with the same name of a symbol you're using in your file.

    So it would be better to post some code, maybe someone spots the error.

    Regards
    Last edited by marcel; 28th May 2007 at 16:43.

  7. #7
    Join Date
    Feb 2007
    Posts
    32
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

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

    Hi marcel,
    It is not possible to put the whole code.

    void MyTextBox::ProcessText()
    {
    char command[]="Line",num[10];
    int pnts[20];
    int k=0,j=0;

    for(int i=0;i<str.length();i++)
    { QChar ch=this->str.at(i);
    if(i<4)
    command[i]=ch.toAscii();

    if(isdigit(ch.toAscii()))
    num[j++]=ch.toAscii();

    if( i>4 && (ch == Qt::Key_Comma || ch==Qt::Key_Space ) )
    { num[j]=0;
    pnts[k++]=atoi(num);
    j=0;
    }
    }
    num[j]=0;
    pnts[k]=atoi(num);



    QString s="";
    s.append(command);

    QPoint P[]={ QPoint(pnts[0],pnts[1]), QPoint(pnts[2],pnts[3]) };

    if(s=="Line")
    myView->DrawLine(P[0],P[1]);
    else if(s=="Circ")
    myView->DrawCircle(P[0],pnts[2],pnts[3]);
    else if(s=="Bezi")
    { if((k+1)%2==0)
    myView->DrawBezier(pnts,k+1);
    else
    {
    QMessageBox *p=new QMessageBox(this);
    p->setText("Invalid Input, Check Help");
    p->setIcon(QMessageBox::Information);
    p->show();
    }
    }
    else
    {
    QMessageBox *p=new QMessageBox();
    p->setText("No such command exist, Check Help");
    p->setIcon(QMessageBox::Information);
    p->show();
    }

    str="";
    prevstr="";
    QKeyEvent *e=new QKeyEvent(QEvent::KeyPress,65,Qt::NoModifier,QStri ng("> "));
    keyPressEvent(e);



    }

    where "MyTextBox" is inherited from QTextBox

  8. #8
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

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

    And are you positive that the error is from that line, where you create the QKeyEvent?

    And what about this?
    Qt Code:
    1. QKeyEvent *e=new QKeyEvent(QEvent::KeyPress,65,Qt::NoModifier,QStri ng("> "));
    To copy to clipboard, switch view to plain text mode 

    There is still a space in the middle of QString.
    Jpn also asked this, and now you have the same error? How is this a copy-paste error?

    Regards

  9. #9
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

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

    I still cannot spot the error.
    Does it compile if you remove that line?

    Apart from the problem you have, this is not correct:
    Qt Code:
    1. QKeyEvent *e=new QKeyEvent(QEvent::KeyPress,65,Qt::NoModifier,QStri ng("> "));
    2. keyPressEvent(e);
    To copy to clipboard, switch view to plain text mode 

    keyPressEvent is not meant to be called like that.
    Use qApp->postEvent instead.

    Regards

  10. #10
    Join Date
    Feb 2007
    Posts
    32
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

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

    Hi Marcel,
    Could you get some clue? I have traced that due to QEvent::KeyPress, the error is coming, Compiler is unable to recognize the the keyword.

  11. #11
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

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

    Could you post the include section from that file?
    All the includes.

    Regards

  12. #12
    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.

  13. #13
    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

  14. #14
    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?

  15. #15

    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

  16. #16
    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: 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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.