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. Circular dependency error: "MainWindow" does not name a type
Forum Updated to NodeBB v4.3 + New Features

Circular dependency error: "MainWindow" does not name a type

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 3.4k Views 2 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.
  • D Offline
    D Offline
    dcbasso
    wrote on last edited by dcbasso
    #1

    I create a custom "Widget" and need to reference to "MainWindow" on this custom widget, but I got problem with circular dependency. So how can I make this works:

    mainwindow.h

    #include <QMainWindow>
    #include <QLocalSocket>
    #include <QTcpSocket>
    #include <QAbstractSocket>
    #include <QTableWidgetItem>
    #include <QHostInfo>
    #include <QDateTime>
    #include <QStandardItemModel>
    #include <QNetworkConfigurationManager>
    #include <statusbarwidget.h>
    
    namespace Ui {
    class MainWindow;
    }
    

    statusbarwidget.h

    #include <QWidget>
    #include <QTimer>
    #include <QNetworkConfigurationManager>
    #include <QNetworkReply>
    #include <QNetworkAccessManager>
    #include <mainwindow.h>
    
    namespace Ui {
    class StatusBarWidget;
    }
    

    Why I need that?
    Because in "MainWindow" have a public method to add messages to logger table component.

    Thanks all for reply!

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

      Hi,

      You are including mainwindow.h in statusbarwidget.h and statusbarwidget.h in mainwindow.h, that's your circular dependency.

      In any case, what you are trying to do is bad by design. your public method to add messages should rather be a slot, and you should emit a signal from StatusBarWidget that you will connect in your MainWindow class to the "add messages" slot. That way, StatusBarWidget doesn't need to know anything about MainWindow.

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

      D 1 Reply Last reply
      1
      • A Offline
        A Offline
        alex_malyu
        wrote on last edited by alex_malyu
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          You are including mainwindow.h in statusbarwidget.h and statusbarwidget.h in mainwindow.h, that's your circular dependency.

          In any case, what you are trying to do is bad by design. your public method to add messages should rather be a slot, and you should emit a signal from StatusBarWidget that you will connect in your MainWindow class to the "add messages" slot. That way, StatusBarWidget doesn't need to know anything about MainWindow.

          D Offline
          D Offline
          dcbasso
          wrote on last edited by dcbasso
          #4

          @SGaist I just can't understand how I will connect!
          I litle confused:

          MainWindow.h

          public slots:
              void addToLog(QString message);
          

          StatusBarWidget.h

          signals:
              void addToLog(QString message);
          

          StatusBarWidget.cpp

          connect(this, SIGNAL(addToLog(QString)), MainWindow, SLOT(addToLog(QString)));
          

          But I got error:

          /home/dcbasso/workspace_qt/CronoboxDataCapture/statusbarwidget.cpp:36: error: expected primary-expression before ',' token
               connect(this, SIGNAL(addToLog(QString)), MainWindow, SLOT(addToLog(QString)));
          

          I know that I can't make direct reference (appears to be), but I not sure how to pass the mainwindow refence to the widget!
          I try to cast the parent to Mainwindow, but does not works.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dcbasso
            wrote on last edited by
            #5

            Forget it! I pass the wrong parent in widget constructor!
            Know I fix and works great!

            Thank you!

            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