Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. calling mainwindow in constructor

calling mainwindow in constructor

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 780 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    droelf
    wrote on last edited by koahnig
    #1

    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
    {
    public:
        graph(MainWindow w);
    
        ~graph();
        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

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      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.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

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

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved