Important: Please read the Qt Code of Conduct -

Cannot use gl primitives in my mobile application

  • i tried running the following code on a mobile device but i'm getting few errors. the code works fine for desktop or a simulator but shows error for a device..

    'glBegin' was not declared in this scope
    'glVertex3f' was not declared in this scope
    'glEnd' was not declared in this scope

    and so on....

    File name:

    #include "glwidget.h"
    #include <QtOpenGL>

    Glwidget::Glwidget(QWidget *parent) :
    void Glwidget::initializeGL ()
    glClearColor (1,1,0,1);

    void Glwidget::resizeGL (int w, int h){

    void Glwidget::paintGL (){
    glClear (GL_COLOR_BUFFER_BIT);
    qglColor (QColor(255, 0, 0, 127));



    pro file:


    Add files and directories to ship with the application

    by adapting the examples below.

    file1.source = myfile

    dir1.source = mydir

    DEPLOYMENTFOLDERS = # file1 dir1

    symbian:TARGET.UID3 = 0xE0DB25C3

    Allow network access on Symbian

    symbian:TARGET.CAPABILITY += NetworkServices

    If your application uses the Qt Mobility libraries, uncomment

    the following lines and add the respective components to the

    MOBILITY variable.

    CONFIG += mobility


    SOURCES += main.cpp mainwindow.cpp
    glwidget.cpp \

    HEADERS += mainwindow.h
    FORMS += mainwindow.ui

    Please do not modify the following two lines. Required for deployment.


    if anyone finds a solution to the problem kindly help me out..

    thanks :)

    [Edit: Please wrap code in @ blocks. -mlong]

  • in ur .pro file, have u added the following line..

    @QT += opengl@

  • yes i've done this in my pro file

  • Most mobile devices do not have immediate mode OpenGL as they use OpenGL ES. This means all things such as glBegin glVertex are not part of the library and you will have to use either vertex arrays or vertex buffer objects.

    You will also need to use some form of shader as the normal fixed function GL shading is also not present. This is a good place to start.

  • okay.. got it.. thanks...

Log in to reply