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. [Solved] [Not possible] How can I connect things from other Header Files which are "not declared in this Scope"?
Forum Updated to NodeBB v4.3 + New Features

[Solved] [Not possible] How can I connect things from other Header Files which are "not declared in this Scope"?

Scheduled Pinned Locked Moved General and Desktop
12 Posts 3 Posters 3.3k Views 1 Watching
  • 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.
  • X Offline
    X Offline
    Xander84
    wrote on last edited by
    #2

    You need to create an object of Toollist before you can connect any signal/slot connection. I guess that is the difference you had just 1 class before and now you have 2, so you need an objects for both classes to connect them.
    But I don't know to be honest your code snippets look a little weird to me :D

    1 Reply Last reply
    0
    • MeerMusikM Offline
      MeerMusikM Offline
      MeerMusik
      wrote on last edited by
      #3

      [quote author="Xander84" date="1395928169"]You need to create an object of Toollist before you can connect any signal/slot connection. I guess that is the difference you had just 1 class before and now you have 2, so you need an objects for both classes to connect them.
      But I don't know to be honest your code snippets look a little weird to me :D[/quote]

      Ok thanks for the Hint. Going back to the Tutorials...

      1 Reply Last reply
      0
      • MeerMusikM Offline
        MeerMusikM Offline
        MeerMusik
        wrote on last edited by
        #4

        Evening.

        After I took another Look at it, i finally managed to get the Stuff working:

        A.) I created a new Header+CPP File and moved all the Stuuf over there
        B.) Created a class for the Actions and the Menu
        C.) Create and Call the Object of the Class from the "mainwindow.cpp"

        One Error gone. So far so good. But:
        After I have moved all the things to a seperate Header+Class File to get a cleaner mainwindow.cpp, the Compiler now tells me

        "Invalid use of incomplete type QAction"

        sigh -.- Well one thing after another.

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

          Hi,

          You are missing

          @#include <QAction>@

          In the cpp file where you are using it

          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
          • MeerMusikM Offline
            MeerMusikM Offline
            MeerMusik
            wrote on last edited by
            #6

            ROFL Oh my yes you are right. Such a dumb mistake. I moved all other #include Files over from mainwindow.cpp. But I forgot that one somehow.

            Anyway: I am sure I had remembered this in the next few Minutes but thanks for saving me some time :)

            If nothing else related to this comes up, i will finally declare this Topic as Solved.

            Greetings
            Oliver

            [quote author="SGaist" date="1405368983"]Hi,

            You are missing

            @#include <QAction>@

            In the cpp file where you are using it[/quote]

            1 Reply Last reply
            0
            • MeerMusikM Offline
              MeerMusikM Offline
              MeerMusik
              wrote on last edited by
              #7

              Oh fantastic: Now i get

              "undefined Reference to actionsCreate::createActions" and
              "undefined Reference to menuCreate::createMenu in mainwindow.cpp"

              But the classes and Functions are still in menueactions.h and menueactions.cpp

              In mainwindow.cpp i call:
              @
              //For the Actions...
              actionsCreate newActions;
              newActions.createActions();

              //For the Menu...
              menuCreate newMainMenu;
              newMainMenu.createMenu();
              @

              actionsCreate and menuCreate are the Names of the Classes. createActions and createMenu are the Functions within the classes.

              I have changed nothing. Did a clean -> qmake -> rebuild, restarted Creator but nothing. Strange. It just stopped working.

              Has anyone an Idea?

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

                Aren't you moving a bit too much stuff around ? Why a new class for the actions and the menu bar ?

                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
                • MeerMusikM Offline
                  MeerMusikM Offline
                  MeerMusik
                  wrote on last edited by
                  #9

                  I want the mainwindow.cpp as clean as possible. I want to learn to write good and clean code even if i will never make money of it. Its a personal thing.

                  But I needed to create Objects of/for the Functions to be able to have a working Menu and creating those classes works for me.

                  Is there a better Solution?

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

                    Then have a look at Qt's example/demos coding style. They are pretty clean.

                    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
                    • MeerMusikM Offline
                      MeerMusikM Offline
                      MeerMusik
                      wrote on last edited by
                      #11

                      Evening.

                      I found a little time and got things to work. Even all Segmentation Faults are gone. But as usual i ran into another Problem:

                      Having my Menu and Actions combined into MenueActions.cpp, I now call the Menu and Action Creation like this:

                      In MainWindow.cpp:
                      @
                      //Creating an Object of MenueActions...
                      MenueActions mainWindowMainMenu;
                      //Using the Object and call MenueActions::createMenu()...
                      mainWindowMainMenu.createMenu();
                      @

                      The Code in MenueActions.cpp -> createMenu() is:
                      @
                      void MenueActions::createMenu()
                      {
                      mainWindowMainMenuBar = new QMenuBar(0);

                      Datei = new QMenu(0);
                      Datei=mainWindowMainMenuBar->addMenu(tr("&Datei"));
                      dateiNeu = new QAction(tr("Neue leere Datei erzeugen"), this);
                      connect(dateiNeu,SIGNAL(triggered()), this, SLOT(Neu()));
                      Datei->addAction(dateiNeu);
                      dateiNeu->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N));
                      dateiNeu->setWhatsThis(tr("Erzeugt eine neue leere Text Datei"));
                      dateiNeu->setStatusTip(tr("Erzeugt eine neue leere Text Datei"));
                      dateiNeu->setToolTip(tr("Erzeugt eine neue leere Text Datei"));
                      

                      [Cutted out the "same code" for other Menu Entrys...]

                      mainWindowMainMenuBar->addMenu(Datei);
                      mainWindowMainMenuBar->addMenu(PADs);
                      mainWindowMainMenuBar->addMenu(Tools);
                      mainWindowMainMenuBar->addMenu(Hilfe);
                      

                      }
                      @

                      No Errors but the Menu dont show up in the MainWindow of the Application. Using "show();" just execute the Menu (in a second Window). So i disabled that again.

                      I am using a Layout. The current Code within mainwindow.cpp is:

                      @
                      mainWindowWidget = new QWidget(this);

                      //Main Layout!
                      qGridLayout = new QGridLayout;
                      

                      LinkListe = new QTextEdit;
                      LinkListe->setReadOnly(true);

                      //Einfacher Texteditor (Zu Beginn nur ein simpler Dateibetrachter!)
                      TextEditor = new QTextEdit;
                      TextEditor->setReadOnly(true);
                      
                      OpenAntrag = new QTextEdit;
                      OpenAntrag->setReadOnly(true);
                      
                      statusBar = new QStatusBar;
                      statusBar->setEnabled(true);
                      statusBar->show();
                      statusBar->showMessage(tr("I am the Statusbar"), 90000);
                      

                      statusBarLayout = new QHBoxLayout;
                      statusBarLayout->addWidget(statusBar);

                      layoutLinkListe = new QVBoxLayout;
                      layoutLinkListe->addWidget(LinkListe);

                      layoutTextEditor = new QVBoxLayout;
                      layoutTextEditor->addWidget(TextEditor);
                      
                      layoutOpenAntrag = new QVBoxLayout;
                      layoutOpenAntrag->addWidget(OpenAntrag);
                      
                      qGridLayout->addLayout(layoutLinkListe, 0,0);
                      
                      qGridLayout->addLayout(layoutTextEditor, 0,1);
                      
                      qGridLayout->addLayout(layoutOpenAntrag, 0,2);
                      qGridLayout->addLayout(statusBarLayout, 1,0);
                      
                      mainWindowWidget->setLayout(qGridLayout);
                      
                      MenueActions mainWindowMainMenu;
                      mainWindowMainMenu.createMenu();
                      
                      setCentralWidget(mainWindowWidget);
                      mainWindowWidget->show();
                      

                      @

                      I have found a dozen of Tips for Qt 4.x - but that haven't helped me in anyway: Functions like "exec()" or "run()" are not available under Qt 5.3.1

                      Should i create an extra Class and put the Layout and Menu Creation into one?

                      Thanks and good night :)
                      Oliver

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

                        There's no need for mainWindowMainMenuBar, QMainWindow already has a menu bar that you can retrieve with menuBar()

                        As for why it doesn't show, you don't put it in any layout nor are you calling show on it.

                        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