Qt Forum

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

    Call for Presentations - Qt World Summit

    Signal Slot connection from different classes

    General and Desktop
    8
    20
    21227
    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.
    • H
      huckfinn last edited by

      [quote author="rokemoon" date="1313050079"]
      // here you need the pointer
      connect( &ref2ClassB, SIGNAL(trigger_Do_Some(int, int)), this, SLOT( slot_Do_Some(int, int)) );
      [/quote]

      This way I get an error C2594: 'argument' : ambiguous conversions from 'Class_B *' to 'const QObject *'

      1 Reply Last reply Reply Quote 0
      • R
        rokemoon last edited by

        Class_B must inherite QObject (directly or indirectly), can you give us latest code of your Class_B?

        1 Reply Last reply Reply Quote 0
        • H
          huckfinn last edited by

          Latest Class_B:
          @
          #include <QtCore/QThread>

          template class SWITCHEXPORT QMap< int, QString >;

          class Class_A;
          class QModelIndex;

          class SWITCHEXPORT Class_B : public QThread {
          Q_OBJECT

          public:
          /// @brief Constructor
          Class_B( void );

          void aMethod();

          signal:
          void trigger_Do_Some(int, int);

          private:
          QMap< int, QString > categoryNameByID;
          }
          @

          1 Reply Last reply Reply Quote 0
          • R
            rokemoon last edited by

            Can you tell us why you use QThread? Can you try inherite from QObject and tell us about result?

            1 Reply Last reply Reply Quote 0
            • H
              huckfinn last edited by

              There is a @QThread::start();@ in the source .cpp .

              So when I inherit from both @clas.s Class_B : public QThread, public QObject@ and I am able to compile it.

              But now I have linking errors:
              @
              3>Linking...
              3> Creating library C:\MyProject\Debug\MyProject.lib and object C:\MyProject\Debug\MyProject.exp
              3>Class_B.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const Class_B::staticMetaObject" (?staticMetaObject@Class_B@@2UQMetaObject@@B)
              3>Class_A.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const Class_B::staticMetaObject" (?staticMetaObject@Class_B@@2UQMetaObject@@B)
              3>Class_3.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const Class_B::staticMetaObject" (?staticMetaObject@Class_B@@2UQMetaObject@@B)
              3>Class_B.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall Class_B::metaObject(void)const " (?metaObject@Class_B@@UBEPBUQMetaObject@@XZ)
              3>Class_B.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall Class_B::qt_metacast(char const *)" (?qt_metacast@Class_B@@UAEPAXPBD@Z)
              3>Class_B.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall Class_B::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@Class_B@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
              3>Class_B.obj : error LNK2019: unresolved external symbol "protected: void __thiscall Class_B::trigger_Do_Some(long,long)" (?trigger_Do_Some@Class_B@@IAEXJJ@Z) referenced in function "public: virtual void __thiscall Class_B::HandleMessage(void * const)" (?HandleMessage@Class_B@@UAEXQAX@Z)
              3>C:\MyProject\Debug\MyProject.dll : fatal error LNK1120: 5 unresolved externals
              @

              1 Reply Last reply Reply Quote 0
              • M
                mrtc3 last edited by

                When you have added Q_OBJECT to Class_B.h recently, then assure yourself that moc_ClassB.cxx has been generated as well.
                If that is the case, this moc-file should be listed in the .pro or .vcpro file as Source
                e.g.:
                @
                <Files>
                <Filter Name="Source Files">
                <File RelativePath="C:\path\moc_Class_B.cxx">
                </File>
                <!-- ....etc...-->
                @

                There are 10 types. Those who understand binary and those who don't .)

                1 Reply Last reply Reply Quote 0
                • H
                  huckfinn last edited by

                  I added these tags to the vcpro file, now I can compile and run my application.

                  However, now I have a
                  @
                  warning C4584: 'Class_B' : base-class 'QObject' is already a base-class of 'OtherClass'
                  @

                  I dont like warnings :(

                  1 Reply Last reply Reply Quote 0
                  • L
                    loladiro last edited by

                    Multiple inheritance is NOT supported for QObject based classes. Can you change your code?

                    1 Reply Last reply Reply Quote 0
                    • R
                      Ramin7000 last edited by

                      main.cpp :
                      @
                      #include <QtGui>
                      #include <converter.h>

                      int main(int argc,char *argv[])
                      {
                      QApplication app(argc,argv);

                      QGraphicsScene scene(0,0,500,300);
                      QGraphicsView view(&scene);
                      
                      QLabel *l = new QLabel();
                      QSlider *s = new QSlider();
                      
                      l->setText("Move the slider handle");
                      s->setOrientation(Qt::Horizontal);
                      
                      l->setGeometry(100,100,150,50);
                      s->setGeometry(100,200,150,50);
                      
                      Converter *ms = new Converter(s,l);
                      
                      
                      scene.addWidget(l);
                      scene.addWidget(s);
                      
                      view.show();
                      return app.exec&#40;&#41;;
                      

                      }@

                      converter.cpp :
                      @
                      #include "converter.h"

                      Converter::Converter(QSlider *s, QLabel *l)
                      {
                      connect(s,SIGNAL(valueChanged(int)),this,SLOT(Changer(int)));
                      connect(this,SIGNAL(Changer(QString)),l,SLOT(setText(QString)));
                      }

                      void Converter::Changer(int x)
                      {
                      Changer(QString::number(x));
                      }
                      @

                      converter.h :
                      @
                      #ifndef CONVERTER_H
                      #define CONVERTER_H

                      #include <QtGui>

                      class Converter : public QObject
                      {
                      Q_OBJECT

                      public:
                      Converter(QSlider*,QLabel*);

                      protected slots:
                      void Changer(int);

                      signals:
                      void Changer(QString);

                      };

                      #endif // CONVERTER_H
                      @

                      [Edit: Please use @ tags around code. I have added them here. -- mlong]

                      Ramin Lohrasbi

                      1 Reply Last reply Reply Quote 0
                      • V
                        vittalonline last edited by

                        Use Q_PROPERTY for passing arguments in Class-B

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post