Seite 1 von 1

OpenGL Meldung: Must construct a QApplication before a QPain

Verfasst: 19. Oktober 2008 17:51
von MatthiasA
Hallo,

habe VisualStudio 2008 Pro und Qt 4.4.3 OpenSource

wenn ich ein Beispiel zu OpenGL kompilieren möchte,
taucht in einem Dos Fenster die Fehlermeldung
QWidget: Must construct a QApplication before a QPaintDevice
auf, warum?

Code: Alles auswählen

#include <QApplication>
#include "mainwindow.h"

 int main(int argc, char *argv[])
 {
     QApplication app(argc, argv);
	 MainWindow mw;
	 mw.showMaximized();
	 mw.show();
     return app.exec();
 }

in MainWindow
habe ich 2 DockWidgets
ohne OpenGL funktioniert die GUI
mit OpenGL in einem Widget taucht der oben genannte Fehler auf.

Wenn ich ein fertiges QT Beispiel mit Opengl kompiliere
taucht er auch auf ( bei jedem)

kann mir da jemand weiterhelfen?
Dankeschön!

Gruß Matthias

Verfasst: 19. Oktober 2008 22:08
von solarix
Funktionieren die Beispiele, wenn du das Projekt ausserhalb der IDE (also im Command-Prompt) generierst?

Verfasst: 19. Oktober 2008 22:20
von Christian81
wie sieht mainwindow.h/.cpp aus?

Verfasst: 20. Oktober 2008 20:36
von MatthiasA
Hallo

anbei die mainwindow

Code: Alles auswählen

#pragma once

#include <QMainWindow>
#include <QLabel>
#include <QtGui>
#include <QTabWidget>
#include <QGLWidget>

class MainWindow : public QMainWindow
{
	Q_OBJECT

	private:
		
		QLabel *label1;
		QLabel *label2;
		QTabWidget *widget;
		QTabWidget *widget1;
		
		void createDockWindows()
		{

			QDockWidget *dock = new QDockWidget(tr("Customers"), this);
			dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::BottomDockWidgetArea);
			
			widget = new QTabWidget(dock);

			QGLWidget *Test1 = new QGLWidget;
			QWidget *Test2 = new QWidget;
			
			dock->setWidget(widget);
			addDockWidget(Qt::LeftDockWidgetArea, dock);



			dock = new QDockWidget(tr("Docklinks"), this);
			dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::BottomDockWidgetArea);
			
			widget1 = new QTabWidget(dock);
			widget1->addTab(Test1,"label1");
			widget1->addTab(Test2,"label2");
			
			dock->setWidget(widget1);
			addDockWidget(Qt::BottomDockWidgetArea, dock);

	   };
	
	public:
		MainWindow()
		{
			setWindowTitle(tr("Lego"));
			resize(800,600);

			QLabel *label = new QLabel("<center>Zentral</center>");
			setCentralWidget(label);
			label->setAlignment(Qt::AlignCenter);
			createDockWindows();
		}
	

};



in der steht unter Präprozessoranweisung

Befehlszeile
$(QTDIR)\bin\moc.exe “$(InputPath)” -o “$(InputDir)moc_$(InputName).cpp”

zus Abhängikeiten
$(InputDir)moc_$(InputName).cpp




in der Dos Zeile mit qmake bringt er folgendes

Code: Alles auswählen

C:\Dokumente und Einstellungen\Matze\Eigene Dateien\qtproject\qtproject>qmake -o
 Makefile hellogl.pro

C:\Dokumente und Einstellungen\Matze\Eigene Dateien\qtproject\qtproject>make
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro
make -f Makefile.Debug
make[1]: Entering directory `C:/Dokumente und Einstellungen/Matze/Eigene Dateien
/qtproject/qtproject'
Makefile.Debug:59: *** missing separator.  Stop.
make[1]: Leaving directory `C:/Dokumente und Einstellungen/Matze/Eigene Dateien/
qtproject/qtproject'
make: *** [debug] Error 2

C:\Dokumente und Einstellungen\Matze\Eigene Dateien\qtproject\qtproject>
bei nmake gibt er folgendes aus

Code: Alles auswählen


C:\Dokumente und Einstellungen\Matze\Eigene Dateien\qtproject\qtproject>nmake ma
in.cpp

Microsoft (R) Program Maintenance Utility, Version 9.00.21022.08
Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.

main.cpp(4) : fatal error U1033: Syntaxfehler: "int" unerwartet
Stop.

C:\Dokumente und Einstellungen\Matze\Eigene Dateien\qtproject\qtproject>
in er hellogl.pro steht

Code: Alles auswählen


 HEADERS       = mainwindow.h 
 SOURCES       = main.cpp
 QT           += opengl

 # install
 target.path = $$[QT_INSTALL_EXAMPLES]/opengl/hellogl
 sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS hellogl.pro
 sources.path = $$[QT_INSTALL_EXAMPLES]/opengl/hellogl
 INSTALLS += target sources





an der Beispiel datei macht er ewig rum und schreibt immer wieder
das in die kosnole

Code: Alles auswählen



C:\QT\4.4.3\examples\opengl\hellogl>qmake -o Makefile hellogl.pro

C:\QT\4.4.3\examples\opengl\hellogl>make
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro
.
.
.
.


Verfasst: 20. Oktober 2008 22:27
von solarix

Code: Alles auswählen

C:\Dokumente und Einstellungen\Matze\Eigene Dateien\qtproject\qtproject
Kannst du das ganze nochmal versuchen, jedoch in einem Verzeichnis ohne Leerzeichen? z.B:

Code: Alles auswählen

C:\source\qtproject
[edit]
und zuerst das projekt-file mal neu erstellen

Code: Alles auswählen

$ make distclean
$ qmake -project "QT += opengl" "CONFIG += console"
$ qmake
$ make
....?

Verfasst: 22. Oktober 2008 20:17
von MatthiasA
hab ich doch oben das Beispiel file befindet sch in einem ordner ohne leerzeichen und neu erstellt hab ich das projektfile auch

Verfasst: 22. Oktober 2008 20:33
von solarix
hab ich doch oben das Beispiel file befindet sch in einem ordner ohne leerzeichen
vergiss mal das example.. versuche einfach dein "Hello-World". Wenn nicht mal das funktioniert, wie sollen dann grössere Projekte anspringen?
und neu erstellt hab ich das projektfile auch
nein... wo?

Verfasst: 24. Oktober 2008 23:23
von MatthiasA
C:\QT\4.4.3\examples\opengl\hellogl>qmake -o Makefile hellogl.pro

C:\QT\4.4.3\examples\opengl\hellogl>make
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro
c:\qt\4.4.3\bin\qmake.exe -win32 -o Makefile hellogl.pro


hier hab ich das makefile neu erstellt

Verfasst: 24. Oktober 2008 23:43
von MatthiasA
okay es funktioniert im visual studio ;-)

Verfasst: 25. Oktober 2008 11:14
von solarix
hier hab ich das makefile neu erstellt
ich habe nicht "makefile" geschrieben, sondern "Projektfile".. :roll:
okay es funktioniert im visual studio
und woran lag's jetzt genau?

Verfasst: 26. Oktober 2008 11:51
von MatthiasA
es lag an den Einträgen

QT_BEGIN_NAMESPACE

und

QT_END_NAMESPACE

die habe ich in jeder Header Datei gelöscht
und neu kompiliert, nun klappt es

vielen vielen Dank für die Mühe

Gruß Matthias Asselborn

Verfasst: 26. Oktober 2008 16:33
von MatthiasA

Code: Alles auswählen


1>------ Erstellen gestartet: Projekt: qtproject, Konfiguration: Release Win32 ------
1>Ein benutzerdefinierter Buildschritt wird ausgeführt.
1>Ein benutzerdefinierter Buildschritt wird ausgeführt.
1>Verknüpfen...
1>glwidget.obj : error LNK2001: Nicht aufgelöstes externes Symbol "__imp__glDeleteLists@8".
1>glwidget.obj : error LNK2001: Nicht aufgelöstes externes Symbol "__imp__glClear@4".
1>glwidget.obj : error LNK2001: Nicht aufgelöstes externes Symbol "__imp__glOrtho@48".
1>glwidget.obj : error LNK2001: Nicht aufgelöstes externes Symbol "__imp__glEnd@0".
1>glwidget.obj : error LNK2001: Nicht aufgelöstes externes Symbol "__imp__glVertex3d@24".
1>glwidget.obj : error LNK2001: Nicht aufgelöstes externes Symbol "__imp__glBegin@4".
1>glwidget.obj : error LNK2001: Nicht aufgelöstes externes Symbol "__imp__glShadeModel@4".
1>glwidget.obj : error LNK2001: Nicht aufgelöstes externes Symbol "__imp__glTranslated@24".
1>glwidget.obj : error LNK2001: Nicht aufgelöstes externes Symbol "__imp__glRotated@32".
1>glwidget.obj : error LNK2001: Nicht aufgelöstes externes Symbol "__imp__glEndList@0".
1>glwidget.obj : error LNK2001: Nicht aufgelöstes externes Symbol "__imp__glNewList@8".
1>glwidget.obj : error LNK2001: Nicht aufgelöstes externes Symbol "__imp__glMatrixMode@4".
1>glwidget.obj : error LNK2001: Nicht aufgelöstes externes Symbol "__imp__glViewport@16".
1>glwidget.obj : error LNK2001: Nicht aufgelöstes externes Symbol "__imp__glGenLists@4".
1>glwidget.obj : error LNK2001: Nicht aufgelöstes externes Symbol "__imp__glEnable@4".
1>glwidget.obj : error LNK2001: Nicht aufgelöstes externes Symbol "__imp__glCallList@4".
1>glwidget.obj : error LNK2001: Nicht aufgelöstes externes Symbol "__imp__glLoadIdentity@0".
1>C:\Dokumente und Einstellungen\Matze\Eigene Dateien\qtproject\Release\qtproject.exe : fatal error LNK1120: 17 nicht aufgelöste externe Verweise.
1>Das Buildprotokoll wurde unter "file://c:\Dokumente und Einstellungen\Matze\Eigene Dateien\qtproject\qtproject\Release\BuildLog.htm" gespeichert.
1>qtproject - 18 Fehler, 0 Warnung(en)
========== Erstellen: 0 erfolgreich, Fehler bei 1, 0 aktuell, 0 übersprungen ==========

worin liegt nun dieser Fehler?

ich habe folgende libs eingetragen

bei debug

Code: Alles auswählen

qtmaind.lib
QtGuid4.lib
QtCored4.lib
QtOpenGld4.lib
und release ohne d

Verfasst: 26. Oktober 2008 17:01
von Christian81
Ist es so schwer eine .pro-Datei zu erstellen und per qmake ein lauffähiges .vcproj zu erstellen wenn man nicht weiß gegen was man alles linken muss? Wo werden wohl OpenGL-Libs definiert sein... :roll:

Verfasst: 26. Oktober 2008 19:33
von Volker
Wo die OpenGL-Libs definiert sind weiß ich nicht, aber die OpenGL Funktionen sind in der opengl32.lib definiert :-)

Verfasst: 26. Oktober 2008 19:57
von MatthiasA
ach die opengl32.lib ist beim vielen rumprobieren verloren gegangen
nun läufts