2013-07-31 15 views
5

Ho creato un'applicazione con Qt Creator (OS Ubuntu 13.04). Una funzione crea una finestra e disegna un grafico usando la libreria GLUT, l'immagine è giusta. Ma quando provo a chiudere la finestra e continuo a lavorare con il mio programma, termina. Come posso evitare questo?Come chiudere la finestra GLUT senza terminare l'applicazione?

C'è il codice della mia funzione:

void plot(int argc, char**argv,.../*other arguments*/) 
{ 
    glutInit(&argc, argv); 
    glutInitDisplayMode(GLUT_RGBA | GLUT_ALPHA); 
    glutCreateWindow("Green Window"); 
    //some code 
    //... 
    glutDisplayFunc(draw); 
    glutMainLoop(); 
}   

stampe in uscita Applicazione" ... terminato con il codice 0"

+0

È questo un progetto di Qt GUI? O stai semplicemente usando Qt Creator per creare un progetto C++ di base? –

+0

Sì, creo la finestra principale con Qt GUI. –

+0

In questo caso, come menzionato @JoachimPileborg, poiché 'glutMainLoop' non ritorna, è necessario utilizzare il supporto integrato di Qt per il rendering OpenGL. –

risposta

1

Se si legge per esempio this reference of glutMainLoop vedrai che glutMainLoop non restituisce mai. Ciò significa che chiamerà direttamente exit invece di tornare.

Se si utilizza Qt, quindi è in grado di aprire finestre contenenti contesti OpenGL, Windows compatibile con il resto di Qt e che è possibile chiudere a piacimento.

2

È possibile passare a freeglut che ha implementato la funzione glutLeaveMainLoop(). Come dice la documentazione:

The glutLeaveMainLoop function causes freeglut to stop its event loop. 

Usage 

void glutLeaveMainLoop (void); 

Description 

The glutLeaveMainLoop function causes freeglut to stop the event loop. If the GLUT_ACTION_ON_WINDOW_CLOSE option has been set to GLUT_ACTION_CONTINUE_EXECUTION, control will return to the function which called glutMainLoop; otherwise the application will exit. 

If the application has two nested calls to glutMainLoop and calls glutLeaveMainLoop, the behaviour of freeglut is undefined. It may leave only the inner nested loop or it may leave both loops. If the reader has a strong preference for one behaviour over the other he should contact the freeglut Programming Consortium and ask for the code to be fixed. 

Changes From GLUT 

GLUT does not include this function. 

Fonte: http://freeglut.sourceforge.net/docs/api.php

Problemi correlati