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. Cant understand Signal Slot Syntax
Forum Updated to NodeBB v4.3 + New Features

Cant understand Signal Slot Syntax

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 1.9k 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.
  • H Offline
    H Offline
    hexenbrennen
    wrote on last edited by
    #1

    Hi

    i have created a little code for understanding the Signal / Slot Syntax but i always get "../blubber.cpp:-1: Error:undefined reference to `vtable for blubber'

    blubber.cpp
    @#include "blubber.h"

    blubber::blubber()
    {
    }

    void blubber::test(){
    emit this->testsignal(10);
    }
    @

    blubber.h
    @#ifndef BLUBBER_H
    #define BLUBBER_H

    #include <QObject>

    class blubber:public QObject
    {
    Q_OBJECT

    public:
    blubber();
    void test();

    signals:
    void testsignal(int);
    };

    #endif // BLUBBER_H
    @

    main.cpp

    @#include <QtGui/QApplication>
    #include "mainwindow.h"
    #include "blubber.h"

    int main(int argc, char *argv[])
    {
    blubber *blub=new blubber;

    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    
    QObject::connect(blub,SIGNAL(testsignal(int)),&w,SLOT(abc(int)));
    
    return a.exec&#40;&#41;;
    

    }
    @

    What i am doing wrong?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      Dimbreath
      wrote on last edited by
      #2

      Did you try running qmake?

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hexenbrennen
        wrote on last edited by
        #3

        thx

        qmake solved this why does this happen?

        1 Reply Last reply
        0
        • U Offline
          U Offline
          utcenter
          wrote on last edited by
          #4

          Do you have the abc(int) slot declared in your MainWindow class? Where do you call the blubber.test() method so the signal is actually emitted??

          Anyway, there is nothing all that complex about the syntax - declaration of signals and slots is straightforward, signals are just declarations, slots are like regular functions.

          When you connect you specify which QObject derived class and which signal you want to connect to which QObject derived class and slot.

          In Qt5 there is additional syntax for signals and slots, allowing to connect signals to either regular functions (not declared as slots) and even inline lambda expressions. It even does compile time checking, which the old syntax does not.
          http://qt-project.org/wiki/New_Signal_Slot_Syntax

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

            [quote author="hexenbrennen" date="1356901927"]thx

            qmake solved this why does this happen?[/quote]

            Sometimes it 'misses' to run qmake.

            1 Reply Last reply
            0
            • C Offline
              C Offline
              ChrisW67
              wrote on last edited by
              #6

              [quote author="hexenbrennen" date="1356901927"]qmake solved this why does this happen?[/quote]

              A vtable is a compiler generated internal table used to handle virtual functions in a class. If the class has no declared virtuals (not inherited) then a vtable is not generated.

              Blubber without the Q_OBJECT macro has no virtuals. Adding Q_OBJECT gives blubber some virtual function declarations that tie to code generated by moc. Until the moc code is generated and linked the now-required vtable is missing.

              Using the Q_OBJECT macro as a marker, qmake arranges Makefile entries to run moc. The Makefile does not have moc commands for the file if the marker is added after qmake is run. Re-running qmake regenerates the Makefile, and a subsequent make runs moc on the file, generates the code, and satisfies the missing linker names.

              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