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. Unresolved external Symbol formInterface::forminterface => Constructor

Unresolved external Symbol formInterface::forminterface => Constructor

Scheduled Pinned Locked Moved General and Desktop
14 Posts 2 Posters 3.1k 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.
  • sierdzioS Offline
    sierdzioS Offline
    sierdzio
    Moderators
    wrote on last edited by
    #4

    If you are pasting the error message here exactly as it is printed, then the matter is simple: you have a typo in the constructor name (forminterface instead of formInterface).

    (Z(:^

    1 Reply Last reply
    0
    • Flaming MoeF Offline
      Flaming MoeF Offline
      Flaming Moe
      wrote on last edited by
      #5

      Mh... i set up a new Project and copyed everything from the first one and then it was ok.

      Since i want to Change a variable inside formInterface.cpp i gave it a Slot "updateValue(int) and gave the Form.h a Signal valueChanged(int)
      and connected them in main
      QObject::connect(test, SIGNAL(valueChanged(int)), FI, SLOT(updateVal(int));
      The updateValue function is
      @
      void formInterface::updateVal(int i)
      {
      val = i;
      std::cout << val << "\n";
      }
      @
      so, everytime the function is triggered i should get an Output, what doesn´t happen. But during compiling i don´t get warnings, that Connection failed.
      Also a cout command in the constructor Comes to Action, when i cancel the window when running...
      Complete Code beneath

      main:
      @#include "main.h"
      using namespace std;

      void main(int argc, char *argv[])
      {

      QApplication app(argc, argv&#41;;
      Form *test = new Form;
      formInterface *FI = new formInterface;
      QObject::connect(test, SIGNAL(valueChanged(int)), FI, SLOT(updateVal&#40;int&#41;&#41;&#41;;
      test->show();
      cout << "TEST\n";
      app.exec&#40;&#41;;
      

      }
      @
      Form.h
      @#ifndef FORM_H
      #define FORM_H

      #include <QWidget>

      namespace Ui {
      class Form;
      }

      class Form : public QWidget
      {
      Q_OBJECT

      public:
      explicit Form(QWidget *parent = 0);
      ~Form();

      private:
      Ui::Form *ui;
      signals:
      void valueChanged(int);
      };

      #endif // FORM_H
      @
      Form.cpp
      @#include "form.h"
      #include "ui_form.h"

      Form::Form(QWidget *parent) :
      QWidget(parent),
      ui(new Ui::Form)
      {
      ui->setupUi(this);
      }

      Form::~Form()
      {
      delete ui;
      }
      @
      forminterface.h
      @#ifndef FORMINTERFACE_H
      #define FORMINTERFACE_H
      #include <QObject>
      class formInterface : public QObject
      {
      Q_OBJECT
      public:
      formInterface();
      public slots :
      void updateVal(int i);

      private:

      int val;
      

      };

      #endif // FORMINTERFACE_H
      @
      formInterface,cpp
      @#include "forminterface.h"
      #include <iostream>

      formInterface::formInterface(): QObject()
      {
      std::cout << "formInterface Konstruktor "<< val << "\n";
      }

      void formInterface::updateVal(int i)
      {
      val = i;
      std::cout << val << "\n";
      }
      @

      A lovely day for a ̶g̶̶u̶̶i̶̶n̶̶n̶̶e̶̶s̶ DUFF^^

      1 Reply Last reply
      0
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #6

        Connections are created at runtime. Check out the console output when the application is running (compiled in debug mode!).

        Just to be sure, please use qDebug() instead of std::cout.

        In order to updateVal() to be triggered, you need to emit the valueChanged() signal somewhere in Form class. I don't see any place where you do that.

        (Z(:^

        1 Reply Last reply
        0
        • Flaming MoeF Offline
          Flaming MoeF Offline
          Flaming Moe
          wrote on last edited by
          #7

          At first I tryed to have a member function wich Points to the valueChanged() of the ui

          @
          void Form::valueChanged(int i)
          {
          ui->spinBox->valueChanged(i);
          }@

          But when i´m commenting this code in, i get the error,

          moc_form.obj:-1: error: LNK2005: "public: void __thiscall Form::valueChanged(int)" (?valueChanged@Form@@QAEXH@Z) is allready defined in form.obj

          and plus i have a book which says that code from Signal methods is written by the MOC

          A lovely day for a ̶g̶̶u̶̶i̶̶n̶̶n̶̶e̶̶s̶ DUFF^^

          1 Reply Last reply
          0
          • sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #8

            You have to specify a place where this signal will be emitted. The rest of the magic is done by MOC, indeed. But you need to tell it when to run. This is done by using the emit keyword (not really, but don't worry about that right now).

            You should not define a function that has the same name as your signal! The code you posted in your last post is wrong, and that is precisely why you are not getting any output. The spinbox will emit the signal for you, all you need to do is to connect it to your slot. You do not need to define a signal in your Form class.

            (Z(:^

            1 Reply Last reply
            0
            • Flaming MoeF Offline
              Flaming MoeF Offline
              Flaming Moe
              wrote on last edited by
              #9

              Originally i didn´t had that Signal method in the form.cpp

              So i guess this
              @
              QObject::connect(test, SIGNAL(valueChanged(int)), FI, SLOT(updateVal(int)));
              @
              is wrong and to connect the spinBoxe´s valueChanged somehow i Need to reference the spinbox via the form variable?
              I tryed like this test->ui->... but originally the ui is a private pointer.

              A lovely day for a ̶g̶̶u̶̶i̶̶n̶̶n̶̶e̶̶s̶ DUFF^^

              1 Reply Last reply
              0
              • sierdzioS Offline
                sierdzioS Offline
                sierdzio
                Moderators
                wrote on last edited by
                #10

                Something like this would work, but would require a bit of refactoring:
                @
                connect(ui->spinBox, SIGNAL(valueChanged(int)), formInterfacePointer, SLOT(updateVal(int)));
                @

                Don't worry, I know signals and slots can be confusing in the beginning, but knowing them is well worth the effort.

                You could also create a signal chain and thus expose the spinbox's signal through your Form class, but that's a lesson for later.

                (Z(:^

                1 Reply Last reply
                0
                • Flaming MoeF Offline
                  Flaming MoeF Offline
                  Flaming Moe
                  wrote on last edited by
                  #11

                  I also tryed this
                  @
                  QObject::connect(test->ui->spinBox, SIGNAL(valueChanged(int)), FI, SLOT(updateVal(int)));
                  @
                  but getting the warning, "Usagae of undefined Type Ui::Form" and i should take a look at the declaration. wich is done in Form.h
                  and that "left of ->spinBox must be a pointer to a Class/Struct/Uonion/generic Type"

                  @
                  #ifndef FORM_H
                  #define FORM_H

                  #include <QWidget>

                  namespace Ui {
                  class Form;
                  }

                  class Form : public QWidget
                  {
                  Q_OBJECT

                  public:
                  explicit Form(QWidget *parent = 0);
                  ~Form();
                  Ui::Form *ui;
                  private:

                  signals:
                  void valueChanged(int);

                  };@

                  A lovely day for a ̶g̶̶u̶̶i̶̶n̶̶n̶̶e̶̶s̶ DUFF^^

                  1 Reply Last reply
                  0
                  • sierdzioS Offline
                    sierdzioS Offline
                    sierdzio
                    Moderators
                    wrote on last edited by
                    #12

                    [quote author="Flaming Moe" date="1409809494"]but getting the warning, "Usagae of undefined Type Ui::Form" and i should take a look at the declaration. wich is done in Form.h
                    and that "left of ->spinBox must be a pointer to a Class/Struct/Uonion/generic Type"[/quote]

                    That is because Ui class is not visible from your main() routine. As said, it does take a bit of getting used to.

                    (Z(:^

                    1 Reply Last reply
                    0
                    • Flaming MoeF Offline
                      Flaming MoeF Offline
                      Flaming Moe
                      wrote on last edited by
                      #13

                      Ok, i think i got it.

                      I throwed out the formInterface.h/.cpp and do everything in form.h/.cpp
                      and connect the Signal and the Slot in the constructor.

                      Is the qt Application blocking the outputstream via cout? I get the Output when i Close the app´s window.

                      main:
                      @#include "main.h"
                      using namespace std;

                      void main(int argc, char *argv[])
                      {
                      QApplication app(argc, argv);
                      Form *test = new Form;
                      //formInterface *FI = new formInterface;
                      test->show();
                      cout << "TEST\n";
                      app.exec();
                      }@
                      form.h:
                      @#ifndef FORM_H
                      #define FORM_H
                      #include <iostream>
                      #include <QWidget>

                      namespace Ui {
                      class Form;
                      }

                      class Form : public QWidget
                      {
                      Q_OBJECT

                      public:
                      explicit Form(QWidget *parent = 0);
                      ~Form();
                      Ui::Form *ui;

                      public slots :
                      void updateVal(int i);

                      signals:
                      void valueChanged(int);

                      private:
                      QWidget window;
                      int val;
                      };

                      #endif // FORM_H
                      @
                      form.cpp:
                      @#include "form.h"
                      #include "ui_form.h"

                      Form::Form(QWidget *parent) :
                      QWidget(parent),
                      ui(new Ui::Form)
                      {
                      ui->setupUi(this);
                      QObject::connect(ui->spinBox, SIGNAL(valueChanged(int)), this, SLOT(updateVal(int)));
                      window.setWindowTitle("Hallo Qt");
                      window.setGeometry(30,30,200,200);
                      }

                      void Form::updateVal(int i)
                      {
                      val = i;
                      if(val == 5) window.show();
                      if(val == 7) window.close();
                      std::cout << val << "\n";
                      }

                      Form::~Form()
                      {
                      delete ui;
                      }
                      @

                      A lovely day for a ̶g̶̶u̶̶i̶̶n̶̶n̶̶e̶̶s̶ DUFF^^

                      1 Reply Last reply
                      0
                      • sierdzioS Offline
                        sierdzioS Offline
                        sierdzio
                        Moderators
                        wrote on last edited by
                        #14

                        Yes, it can happen. Better use qDebug().

                        (Z(:^

                        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