Important: Please read the Qt Code of Conduct -

calling mainwindow in constructor

  • Hi,

    i am kind of new to c++ syntax, so my question is:

    1. I have a mainwindow running
    2. i create an object called graph in mainwindow
    3. this "graph" has to use the graphicsscene of my mainwindow

    I tried it this way:
    In graph.cpp

    graph::graph(MainWindow w){
             this->mainW = w;

    In graph.h

    class graph
        graph(MainWindow w);
        typedef map<int, vertex *> vmap;
        vmap work;
        MainWindow mainW;

    I get the following error

    C:\Users\Nutzer\Documents\BlossomAlgorithm\graph.h:54: Fehler: expected ')' before 'w'
         graph(MainWindow w);
    C:\Users\Nutzer\Documents\BlossomAlgorithm\graph.h:59: Error: 'MainWindow' does not name a type
         MainWindow mainW;

    So how do i use it correctly?

    PS: Sry for newbie question :)

    [edit:koahnig] code tags added

  • Did you follow one of the examples e.g. the application example?

    For your example possibly you have not included the header where you define your derived MainWindow class. Possibly you need to add #include "MainWindow.h" in "graph.h" However, this depends on more things e.g. filenaming and others. So it is a kind of wild guess.

  • Lifetime Qt Champion


    To add to @koahnig, you can't copy a QObject derived class so your code will not compile.

Log in to reply