Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    calling mainwindow in constructor

    General and Desktop
    3
    3
    627
    Loading More Posts
    • 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
      droelf last edited by koahnig

      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 Reply Quote 0
      • K
        koahnig last edited by

        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 Reply Quote 0
        • SGaist
          SGaist Lifetime Qt Champion last edited by

          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 Reply Quote 0
          • First post
            Last post