0
votes

Well, its first time i am using QT. Am i missing some frameworks or something? I am using this tutorial https://youtu.be/8ntEQpg7gck?list=PLMgDVIa0Pg8WrI9WmZR09xAbfXyfkqKWy (or its just outdated, i don't know)

code:

#include <QApplication>
#include <QGraphicsScene>
#include <QGraphicsRectItem>
#include <QGraphicsView>


int main(int argc, char *argv[])
{
    QApplication a(int argc, argv);

    //Creating a scene
    QGraphicsScene * scene = New QGraphicsScene();

    //Create an item
    QGraphicsRectItem * rect = New QGraphicsRectItem();
    rect->setRect(0,0,100,100);

    //Adding item into scene
    scene->addItem(rect);

    return a.exec();
}

errors:

C:\Users\Krzysztof\Documents\QT\Gra\Gra\main.cpp:9: error: C2061: syntax error: identifier 'argv' C:\Users\Krzysztof\Documents\QT\Gra\Gra\main.cpp:12: error: C2065: 'New': undeclared identifier C:\Users\Krzysztof\Documents\QT\Gra\Gra\main.cpp:12: error: C2146: syntax error: missing ';' before identifier 'QGraphicsScene' C:\Users\Krzysztof\Documents\QT\Gra\Gra\main.cpp:15: error: C2065: 'New': undeclared identifier C:\Users\Krzysztof\Documents\QT\Gra\Gra\main.cpp:15: error: C2146: syntax error: missing ';' before identifier 'QGraphicsRectItem' C:\Users\Krzysztof\Documents\QT\Gra\Gra\main.cpp:21: error: C2228: left of '.exec' must have class/struct/union

2

2 Answers

2
votes

First point, consider the line...

QApplication a(int argc, argv);

The compiler will parse that as a function declaration up to and including the int argc,. It then encounters the token argv but notes that argv is a variable rather than a type and fails accordingly.

The line should be...

QApplication a(argc, argv);

Secondly, New --> new -- C++ is case sensitive.

0
votes

"New" should be lowercase. C++ is case sensitive.

Apart from that, this code won't show anything on screen: there's no window, no graphics widget.

I suggest to have a look at the Qt documentation and the related examples.