Where is PeekMessage Func in Qt SDK?



  • @
    if (PeekMessage(&Message,NULL,0,0,PM_REMOVE)) {
    if (Message.message==WM_QUIT)
    break;
    TranslateMessage(&Message);
    DispatchMessage(&Message);
    }
    else {
    Render()
    }
    @

    I want this code in Qt

    but i can not find PeekMessage in Qt SDK

    someone help me please

    [EDIT: code formatting, please wrap in @-tags, Volker]


  • Moderators

    Can you please provide some context to this code? What is it supposed to do and where is it supposed to run?



  • This is not how Qt works. See "The Event System":http://developer.qt.nokia.com/doc/qt-4.8/eventsandfilters.html and "QApplication":http://developer.qt.nokia.com/doc/qt-4.8/qapplication.html, especially QCoreApplication::processEvents() and QCoreApplication::exec().



  • I want rendering in (windows, linux, mac) use OpenGL

    @if( no event ) // if there is no event in loop
    {
    RenderScene(); // I want rendering my scene
    }
    else // if events in loop
    {
    processEvent(); // get them!
    }@


  • Moderators

    Use QGLWidget, then. No need to go into the event loop itself (probably. It does, of course, depend on what you want to achieve).



  • Inherit from QGLWidget and use a QTimer to schedule your renders.



  • thank you all!

    QGLWidget and QTimer is solve my problem!

    but in this case, my program is crash!

    @class Display : public QGLWidget
    {
    Q_OBJECT
    public:
    Display(QWidget *parent = 0);
    ~Display();

    public:
    void resizeGL(int w, int h);
    void initializeGL();
    void paintGL();

    signals:

    public slots:
    };

    void Display::resizeGL(int w, int h)
    {
    }

    void Display::initializeGL()
    {
    }

    void Display::paintGL()
    {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glClearColor(0.0, 0.0, 0.0, 1.0);

    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    
    glBegin(GL_QUADS);
    
    glVertex3f(-0.5, 0.0, -0.5);
    glVertex3f( 0.5, 0.0, -0.5);
    glVertex3f( 0.5, 0.0,  0.5);
    glVertex3f(-0.5, 0.0,  0.5);
    
    glEnd();
    
    QTimer::singleShot(0, this, SLOT(updateGL()));
    

    }@

    .....hmm Why? Why this code is crash?

    it is just draw one polygon. :(



  • Hi,

    why do you trigger a repaint in the repaint? That does not make sense.
    And where exactly does it crash? You needn't trigger the repaint, it is sufficient to it if something changes.

    By the way, a side not to your first post: you said you want to run this on multiple üöatforms. The code (Peek/Translate/DispatchMessage) is win32 API ;-)



  • why do you trigger a repaint in the repaint? >>

    without QTimer::singleShot(0, this, SLOT(updateGL()))
    paintGL() Func is not repaint in this case

    @void Display::paintGL()
    {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glClearColor(0.0, 0.0, 0.0, 1.0);

    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    
    
    static int Angle = 0;
    
    ++Angle;
    
    glPushMatrix();
    glRotatef(Angle, 0.0f, 0.0f, 1.0f);
    glBegin(GL_QUADS);
    
    glVertex3f(-0.5, 0.0, -0.5);
    glVertex3f( 0.5, 0.0, -0.5);
    glVertex3f( 0.5, 0.0,  0.5);
    glVertex3f(-0.5, 0.0,  0.5);
    
    glEnd();
    glPopMatrix();
    

    }@

    where exactly does it crash? >>

    it is not crash all the time
    and it's crash point is not same all the time
    and this crash is fixed QTimer::singleShot Func's msec value change (0 -> 10)

    By the way, a side not to your first post>>

    I'm sorry. and thank you for your Advice Gerolf :)

    and thank you all. dude!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.