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. No appropriate default constructor available

No appropriate default constructor available

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 1.6k 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.
  • L Offline
    L Offline
    lfreeman6490
    wrote on last edited by
    #1

    I am trying to build my QT application to no avail. The error I am getting is

    C2512: "Ui:Pathloss": no appropriate default constructor available

    Even though in my pathloss.h file I have this

    #define PATHLOSS_H
    
    #include <QWidget>
    
    namespace Ui {
    class Pathloss;
    }
    
    class Pathloss : public QWidget
    {
        Q_OBJECT
        
    public:
        Pathloss::Pathloss(QWidget *parent=NULL);
        ~Pathloss();
    
    private:
        Ui::Pathloss *ui;
    };
    
    #endif // PATHLOSS_H
    
    code_text
    

    I am new to c++ and QT, but I believe that

    public:
        Pathloss::Pathloss(QWidget *parent=NULL);
    

    should be my default constructor, is that not correct?

    KroMignonK 1 Reply Last reply
    0
    • L lfreeman6490

      I am trying to build my QT application to no avail. The error I am getting is

      C2512: "Ui:Pathloss": no appropriate default constructor available

      Even though in my pathloss.h file I have this

      #define PATHLOSS_H
      
      #include <QWidget>
      
      namespace Ui {
      class Pathloss;
      }
      
      class Pathloss : public QWidget
      {
          Q_OBJECT
          
      public:
          Pathloss::Pathloss(QWidget *parent=NULL);
          ~Pathloss();
      
      private:
          Ui::Pathloss *ui;
      };
      
      #endif // PATHLOSS_H
      
      code_text
      

      I am new to c++ and QT, but I believe that

      public:
          Pathloss::Pathloss(QWidget *parent=NULL);
      

      should be my default constructor, is that not correct?

      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by
      #3

      @lfreeman6490 said in No appropriate default constructor available:

      With this piece of code, you are defining a class called Pathloss in namespace Ui (full name is Ui::Pathloss)

      namespace Ui {
      class Pathloss;
      }

      With piece of code you a declaring class Pathloss without namespace:

      class Pathloss : public QWidget
      {
      ...
      };

      So they are 2 different classes.
      If you want to declare the class outside the namespace, you have to give full class name:

      class Ui::Pathloss : public QWidget
      {
      ...
      };
      

      cf:

      • https://www.cplusplus.com/doc/tutorial/namespaces/
      • https://www.tutorialspoint.com/cplusplus/cpp_namespaces.htm
      • https://www.geeksforgeeks.org/namespace-in-c/

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      L 2 Replies Last reply
      4
      • Kent-DorfmanK Offline
        Kent-DorfmanK Offline
        Kent-Dorfman
        wrote on last edited by
        #2

        and what namespace owns Pathloss?...hint hint

        1 Reply Last reply
        2
        • L lfreeman6490

          I am trying to build my QT application to no avail. The error I am getting is

          C2512: "Ui:Pathloss": no appropriate default constructor available

          Even though in my pathloss.h file I have this

          #define PATHLOSS_H
          
          #include <QWidget>
          
          namespace Ui {
          class Pathloss;
          }
          
          class Pathloss : public QWidget
          {
              Q_OBJECT
              
          public:
              Pathloss::Pathloss(QWidget *parent=NULL);
              ~Pathloss();
          
          private:
              Ui::Pathloss *ui;
          };
          
          #endif // PATHLOSS_H
          
          code_text
          

          I am new to c++ and QT, but I believe that

          public:
              Pathloss::Pathloss(QWidget *parent=NULL);
          

          should be my default constructor, is that not correct?

          KroMignonK Offline
          KroMignonK Offline
          KroMignon
          wrote on last edited by
          #3

          @lfreeman6490 said in No appropriate default constructor available:

          With this piece of code, you are defining a class called Pathloss in namespace Ui (full name is Ui::Pathloss)

          namespace Ui {
          class Pathloss;
          }

          With piece of code you a declaring class Pathloss without namespace:

          class Pathloss : public QWidget
          {
          ...
          };

          So they are 2 different classes.
          If you want to declare the class outside the namespace, you have to give full class name:

          class Ui::Pathloss : public QWidget
          {
          ...
          };
          

          cf:

          • https://www.cplusplus.com/doc/tutorial/namespaces/
          • https://www.tutorialspoint.com/cplusplus/cpp_namespaces.htm
          • https://www.geeksforgeeks.org/namespace-in-c/

          It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

          L 2 Replies Last reply
          4
          • KroMignonK KroMignon

            @lfreeman6490 said in No appropriate default constructor available:

            With this piece of code, you are defining a class called Pathloss in namespace Ui (full name is Ui::Pathloss)

            namespace Ui {
            class Pathloss;
            }

            With piece of code you a declaring class Pathloss without namespace:

            class Pathloss : public QWidget
            {
            ...
            };

            So they are 2 different classes.
            If you want to declare the class outside the namespace, you have to give full class name:

            class Ui::Pathloss : public QWidget
            {
            ...
            };
            

            cf:

            • https://www.cplusplus.com/doc/tutorial/namespaces/
            • https://www.tutorialspoint.com/cplusplus/cpp_namespaces.htm
            • https://www.geeksforgeeks.org/namespace-in-c/
            L Offline
            L Offline
            lfreeman6490
            wrote on last edited by lfreeman6490
            #4

            @KroMignon @Kent-Dorfman So I changed that, thank you very much, I fixed the other errors besides one. It's saying that

            C2039: 'setupUi': is not a member of 'Ui::Pathloss'
            

            I'm assuming that has something to do with me changing that name and finding where setupUi is at, thanks again to both of you. I really appreciate it

            1 Reply Last reply
            1
            • KroMignonK KroMignon

              @lfreeman6490 said in No appropriate default constructor available:

              With this piece of code, you are defining a class called Pathloss in namespace Ui (full name is Ui::Pathloss)

              namespace Ui {
              class Pathloss;
              }

              With piece of code you a declaring class Pathloss without namespace:

              class Pathloss : public QWidget
              {
              ...
              };

              So they are 2 different classes.
              If you want to declare the class outside the namespace, you have to give full class name:

              class Ui::Pathloss : public QWidget
              {
              ...
              };
              

              cf:

              • https://www.cplusplus.com/doc/tutorial/namespaces/
              • https://www.tutorialspoint.com/cplusplus/cpp_namespaces.htm
              • https://www.geeksforgeeks.org/namespace-in-c/
              L Offline
              L Offline
              lfreeman6490
              wrote on last edited by lfreeman6490
              #5
              This post is deleted!
              KroMignonK 1 Reply Last reply
              0
              • L lfreeman6490

                This post is deleted!

                KroMignonK Offline
                KroMignonK Offline
                KroMignon
                wrote on last edited by
                #6

                @lfreeman6490 said in No appropriate default constructor available:

                QT is telling me to look in the declaration of Pathloss. When I build this with QMake it builds fine, but when I try to run it it throws the error

                First, it is not Qt, it is Microsoft c++ compiler ;) (Error code C2039, looks like Microsoft compiler error code)

                Then some basics:

                • Qt Creator (which is an IDE, like Microsoft Visual Studio), to edit/compile/run your code.
                • qmake is a build manager (like cmake, messon, etc.): running qmake will update your make file, but not compile the project

                Sorry if I am rude, but your code looks very messy...
                I cannot understand what you are trying to do, it don't make sense to me. So it is not simple to give you useful hints!

                I think you are starting from a code example you have found somewhere in documentation or internet.
                Go back to first version and try to understand how it works and then start to change it step by step.

                It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                L 1 Reply Last reply
                0
                • KroMignonK KroMignon

                  @lfreeman6490 said in No appropriate default constructor available:

                  QT is telling me to look in the declaration of Pathloss. When I build this with QMake it builds fine, but when I try to run it it throws the error

                  First, it is not Qt, it is Microsoft c++ compiler ;) (Error code C2039, looks like Microsoft compiler error code)

                  Then some basics:

                  • Qt Creator (which is an IDE, like Microsoft Visual Studio), to edit/compile/run your code.
                  • qmake is a build manager (like cmake, messon, etc.): running qmake will update your make file, but not compile the project

                  Sorry if I am rude, but your code looks very messy...
                  I cannot understand what you are trying to do, it don't make sense to me. So it is not simple to give you useful hints!

                  I think you are starting from a code example you have found somewhere in documentation or internet.
                  Go back to first version and try to understand how it works and then start to change it step by step.

                  L Offline
                  L Offline
                  lfreeman6490
                  wrote on last edited by
                  #7

                  @KroMignon This was handed to me the other day by someone else and I have been trying to build it. I don't have any c++ experience so that is probably why it seems messy

                  KroMignonK 1 Reply Last reply
                  0
                  • L lfreeman6490

                    @KroMignon This was handed to me the other day by someone else and I have been trying to build it. I don't have any c++ experience so that is probably why it seems messy

                    KroMignonK Offline
                    KroMignonK Offline
                    KroMignon
                    wrote on last edited by
                    #8

                    @lfreeman6490

                    I don't know anything about the software you are trying to build.
                    So I can only guess.
                    I am very sorry, my first answer was not correct. I was not take in account that you are using Qt UI Designer!

                    The Ui namespace is used by Qt Creator / UI Designer to group auto-generated Pathloss code in one namespace. It helps to differentiate between the ui class that is generated from designer ui file and the class that implements the functionality.

                    So the idea, is that you will have:

                    • Ui::Pathloss which holds the UI as created with designer
                    • Pathloss which is the QWidget which will build the widget, it will hold an instance of Ui::Pathloss to build the widget content

                    You can read this article to have more details about this: https://www.meetingcpp.com/blog/items/an-introduction-into-qt-part-ii.html

                    So you could better understand how it works, and how you have to make the modifications you want to do.

                    It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                    1 Reply Last reply
                    1

                    • Login

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