Why do I get these errors C2134, C4430 etc, in VS with QT?
-
I have a task to do an OpenGL application in Visual Studio with the QT add-on.
I am trying to compile the code but I am having some errors. This is happening when I PROMOTE the WIDGET where I want to display the OpenGL stuff, to the class that i have created.
here are the errors:
Error error C2143: syntax error : missing ';' before '*' 32 1 QTOpenGLVS Error error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 32 1 QTOpenGLVS Error error C2065: 'widget' : undeclared identifier 48 1 QTOpenGLVS Error error C2061: syntax error : identifier 'QTOpenGLVS' 48 1 QTOpenGLVS Error error C2065: 'widget' : undeclared identifier 49 1 QTOpenGLVS Error error C2227: left of '->setObjectName' must point to class/struct/union/generic type 49 1 QTOpenGLVS Error error C2065: 'widget' : undeclared identifier 53 1 QTOpenGLVS Error error C2227: left of '->sizePolicy' must point to class/struct/union/generic type 53 1 QTOpenGLVS Error error C2228: left of '.hasHeightForWidth' must have class/struct/union 53 1 QTOpenGLVS Error error C2065: 'widget' : undeclared identifier 54 1 QTOpenGLVS Error error C2227: left of '->setSizePolicy' must point to class/struct/union/generic type 54 1 QTOpenGLVS Error error C2065: 'widget' : undeclared identifier 56 1 QTOpenGLVS Error error C2143: syntax error : missing ';' before '*' 32 1 QTOpenGLVS Error error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 32 1 QTOpenGLVS Error error C2065: 'widget' : undeclared identifier 48 1 QTOpenGLVS Error error C2061: syntax error : identifier 'QTOpenGLVS' 48 1 QTOpenGLVS Error error C2065: 'widget' : undeclared identifier 49 1 QTOpenGLVS Error error C2227: left of '->setObjectName' must point to class/struct/union/generic type 49 1 QTOpenGLVS Error error C2065: 'widget' : undeclared identifier 53 1 QTOpenGLVS Error error C2227: left of '->sizePolicy' must point to class/struct/union/generic type 53 1 QTOpenGLVS Error error C2228: left of '.hasHeightForWidth' must have class/struct/union 53 1 QTOpenGLVS Error error C2065: 'widget' : undeclared identifier 54 1 QTOpenGLVS Error error C2227: left of '->setSizePolicy' must point to class/struct/union/generic type 54 1 QTOpenGLVS Error error C2065: 'widget' : undeclared identifier 56 1 QTOpenGLVS Error error C2143: syntax error : missing ';' before '*' 32 1 QTOpenGLVS Error error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 32 1 QTOpenGLVS Error error C2065: 'widget' : undeclared identifier 48 1 QTOpenGLVS Error error C2061: syntax error : identifier 'QTOpenGLVS' 48 1 QTOpenGLVS Error error C2065: 'widget' : undeclared identifier 49 1 QTOpenGLVS Error error C2227: left of '->setObjectName' must point to class/struct/union/generic type 49 1 QTOpenGLVS Error error C2065: 'widget' : undeclared identifier 53 1 QTOpenGLVS Error error C2227: left of '->sizePolicy' must point to class/struct/union/generic type 53 1 QTOpenGLVS Error error C2228: left of '.hasHeightForWidth' must have class/struct/union 53 1 QTOpenGLVS Error error C2065: 'widget' : undeclared identifier 54 1 QTOpenGLVS Error error C2227: left of '->setSizePolicy' must point to class/struct/union/generic type 54 1 QTOpenGLVS Error error C2065: 'widget' : undeclared identifier 56 1 QTOpenGLVS
The classes that i have are the main.cpp, qtopenglvs.cpp and the header file: qtopenglvs.h
main.cpp:
#include "qtopenglvs.h" #include <QtWidgets/QApplication> #include "MyGlWindow.h" void init(){ } int main(int argc, char *argv[]) { QApplication a(argc, argv); QTOpenGLVS w; w.show(); return a.exec(); }
qtopenglvs.cpp
#include "qtopenglvs.h" #include <GL/glut.h> QTOpenGLVS::QTOpenGLVS(QWidget *parent) : QMainWindow(parent) { ui.setupUi(this); } void QTOpenGLVS::initiliazeGL(){ glClearColor(1, 1, 0, 1); } void QTOpenGLVS::paintGL(){ } void QTOpenGLVS::resizeGL(int w, int h){ }
qtopenglvs.h
#ifndef QTOPENGLVS_H #define QTOPENGLVS_H #include <QtWidgets/QMainWindow> #include "ui_qtopenglvs.h" class QTOpenGLVS : public QMainWindow { Q_OBJECT public: explicit QTOpenGLVS(QWidget *parent = 0); void initiliazeGL(); void paintGL(); void resizeGL(int w, int h); private: Ui::QTOpenGLVSClass ui; }; #endif // QTOPENGLVS_H
EDITED
ui_qtopenglvs.h:/******************************************************************************* * ** Form generated from reading UI file 'qtopenglvs.ui' ** ** Created by: Qt User Interface Compiler version 5.5.1 ** ** WARNING! All changes made in this file will be lost when recompiling UI file! ********************************************************************************/ #ifndef UI_QTOPENGLVS_H #define UI_QTOPENGLVS_H #include <QtCore/QVariant> #include <QtWidgets/QAction> #include <QtWidgets/QApplication> #include <QtWidgets/QButtonGroup> #include <QtWidgets/QHBoxLayout> #include <QtWidgets/QHeaderView> #include <QtWidgets/QMainWindow> #include <QtWidgets/QPushButton> #include <QtWidgets/QSpacerItem> #include <QtWidgets/QVBoxLayout> #include <QtWidgets/QWidget> #include "qtopenglvs.h" QT_BEGIN_NAMESPACE class Ui_QTOpenGLVSClass { public: QWidget *centralWidget; QHBoxLayout *horizontalLayout; QTOpenGLVS *widget; QVBoxLayout *verticalLayout; QSpacerItem *verticalSpacer; QPushButton *pushButton; void setupUi(QMainWindow *QTOpenGLVSClass) { if (QTOpenGLVSClass->objectName().isEmpty()) QTOpenGLVSClass->setObjectName(QStringLiteral("QTOpenGLVSClass")); QTOpenGLVSClass->resize(834, 552); centralWidget = new QWidget(QTOpenGLVSClass); centralWidget->setObjectName(QStringLiteral("centralWidget")); horizontalLayout = new QHBoxLayout(centralWidget); horizontalLayout->setSpacing(6); horizontalLayout->setContentsMargins(11, 11, 11, 11); horizontalLayout->setObjectName(QStringLiteral("horizontalLayout")); widget = new QTOpenGLVS(centralWidget); widget->setObjectName(QStringLiteral("widget")); QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); sizePolicy.setHorizontalStretch(0); sizePolicy.setVerticalStretch(0); sizePolicy.setHeightForWidth(widget->sizePolicy().hasHeightForWidth()); widget->setSizePolicy(sizePolicy); horizontalLayout->addWidget(widget); verticalLayout = new QVBoxLayout(); verticalLayout->setSpacing(6); verticalLayout->setObjectName(QStringLiteral("verticalLayout")); verticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding); verticalLayout->addItem(verticalSpacer); pushButton = new QPushButton(centralWidget); pushButton->setObjectName(QStringLiteral("pushButton")); verticalLayout->addWidget(pushButton); horizontalLayout->addLayout(verticalLayout); QTOpenGLVSClass->setCentralWidget(centralWidget); retranslateUi(QTOpenGLVSClass); QObject::connect(pushButton, SIGNAL(clicked()), QTOpenGLVSClass, SLOT(close())); QMetaObject::connectSlotsByName(QTOpenGLVSClass); } // setupUi void retranslateUi(QMainWindow *QTOpenGLVSClass) { QTOpenGLVSClass->setWindowTitle(QApplication::translate("QTOpenGLVSClass", "QTOpenGLVS", 0)); pushButton->setText(QApplication::translate("QTOpenGLVSClass", "Quit", 0)); } // retranslateUi }; namespace Ui { class QTOpenGLVSClass: public Ui_QTOpenGLVSClass {}; } // namespace Ui QT_END_NAMESPACE #endif // UI_QTOPENGLVS_H
-
Hi and welcome to devnet,
Before going further, are you aware that you are not using the correct base class for your OpenGL widget ?
-
Hi @SGaist,
I was researching about my problem and started to understand how to it works with the base class and the other stuff. I fixed these errors, but now I am having other errors.
- when I add these functions to a class header (which the Widget is promoted to that class): paintGL() and resizeGL(int w, int h); I am getting these errors:
error LNK2001: unresolved external symbol "public: virtual void __cdecl taliWidget::paintGL(void)" (?paintGL@taliWidget@@UEAAXXZ)
error LNK2001: unresolved external symbol "public: virtual void __cdecl taliWidget::resizeGL(int,int)" (?resizeGL@taliWidget@@UEAAXHH@Z)
- If I remove the functions there and execute the code, then it goes almost until the end and it doesn't open em the windows but it says this in the logs:
- 'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\ntdll.dll'. Cannot find or open the PDB file.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\kernel32.dll'. Cannot find or open the PDB file.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\KernelBase.dll'. Cannot find or open the PDB file.
'testClasa2.exe' (Win32): Loaded 'C:\Qt\5.5\msvc2013_64\bin\Qt5Cored.dll'. Symbols loaded.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\user32.dll'. Cannot find or open the PDB file.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\gdi32.dll'. Cannot find or open the PDB file.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\lpk.dll'. Cannot find or open the PDB file.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\usp10.dll'. Cannot find or open the PDB file.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\msvcrt.dll'. Cannot find or open the PDB file.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\shell32.dll'. Cannot find or open the PDB file.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\shlwapi.dll'. Cannot find or open the PDB file.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\ole32.dll'. Cannot find or open the PDB file.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\rpcrt4.dll'. Cannot find or open the PDB file.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\advapi32.dll'. Cannot find or open the PDB file.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\sechost.dll'. Cannot find or open the PDB file.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\ws2_32.dll'. Cannot find or open the PDB file.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\nsi.dll'. Cannot find or open the PDB file.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\mpr.dll'. Cannot find or open the PDB file.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\msvcp120d.dll'. Cannot find or open the PDB file.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\msvcr120d.dll'. Cannot find or open the PDB file.
'testClasa2.exe' (Win32): Loaded 'C:\Qt\5.5\msvc2013_64\bin\Qt5Widgetsd.dll'. Symbols loaded.
'testClasa2.exe' (Win32): Loaded 'C:\Qt\5.5\msvc2013_64\bin\Qt5Guid.dll'. Symbols loaded.
'testClasa2.exe' (Win32): Loaded 'C:\Qt\5.5\msvc2013_64\bin\Qt5OpenGL.dll'. Module was built without symbols.
'testClasa2.exe' (Win32): Loaded 'C:\Qt\5.5\msvc2013_64\bin\Qt5Widgets.dll'. Module was built without symbols.
'testClasa2.exe' (Win32): Loaded 'C:\Qt\5.5\msvc2013_64\bin\Qt5Gui.dll'. Module was built without symbols.
'testClasa2.exe' (Win32): Loaded 'C:\Qt\5.5\msvc2013_64\bin\Qt5Core.dll'. Module was built without symbols.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\msvcp120.dll'. Cannot find or open the PDB file.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\msvcr120.dll'. Cannot find or open the PDB file.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\imm32.dll'. Cannot find or open the PDB file.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\msctf.dll'. Cannot find or open the PDB file.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\cryptbase.dll'. Cannot find or open the PDB file.
'testClasa2.exe' (Win32): Loaded 'C:\Qt\5.5\msvc2013_64\plugins\platforms\qwindowsd.dll'. Symbols loaded.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\winmm.dll'. Cannot find or open the PDB file.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\oleaut32.dll'. Cannot find or open the PDB file.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\uxtheme.dll'. Cannot find or open the PDB file.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\dwmapi.dll'. Cannot find or open the PDB file.
QWidget: Must construct a QApplication before a QWidget
The program '[8820] testClasa2.exe' has exited with code 1 (0x1).
Do you have any idea what's going on? I will Edit my post and add the new code if you want?
-
-
It's because you don't implement them. Also note that these function are valid only for QGLWidget and QOpenGLWidget.
-
Do you have a QApplication instantiated in your main function ?
-