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. Qt emit signals
Qt 6.11 is out! See what's new in the release blog

Qt emit signals

Scheduled Pinned Locked Moved General and Desktop
4 Posts 4 Posters 47.0k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    I can't understand why methods in signals don't need to be defined.
    there is an example that you can find in Qt/examples/opengl/hellogl/glwidget.h,glwidget.cpp
    @signals:
    void xRotationChanged(int angle);
    void yRotationChanged(int angle);
    void zRotationChanged(int angle);
    @

    1 Reply Last reply
    0
    • G Offline
      G Offline
      GentooXativa
      wrote on last edited by
      #2

      Thats beacuse signals only emit themself and their arguments, dont need code to work. You defina what they should do on connections.
      "Check this article":http://qt-project.org/doc/qt-4.7/signalsandslots.html#id-bf5ed240-73e9-4fa9-8792-9bc16480c692

      Jose Vicente Giner Sanchez - Senior Mobile Developer

      www.gigigo.com

      C/ Dr. Zamenhof 36bis, 1ºA 28027 Madrid
      T: +34 917431436

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Sam
        wrote on last edited by
        #3

        A Signal is a method that is emitted rather than executed when called. So we only declare prototypes of signals that might be emitted.

        A Slot is a member function that can be invoked as a result of signal emission. We have to tell the compiler which method has to be treated as slots by putting them in one of the following sections:
        public slots, protected slots or private slots.

        So as per the definition we only declare prototypes of signals that might be emitted. So in the HelloGL example we declare the prototypes

        @signals:
        void xRotationChanged(int angle);
        void yRotationChanged(int angle);
        void zRotationChanged(int angle);@

        and in the implementation file whenever we set the rotation we emit one of these signals and the associated Slot function is called. eg.

        @void GLWidget::setXRotation(int angle)
        {
        //do something then
        emit xRotationChanged(angle);
        updateGL();
        }@

        The signals and slots for the above example are connected in window.cpp file :

        @connect(glWidget, SIGNAL(xRotationChanged(int)), xSlider, SLOT(setValue(int)));@

        For more details you can read "Signals and Slots ":http://books.google.ae/books?id=nyxoEiGHKtoC&printsec=frontcover&source=gbs_ge_summary_r&cad=0#v=onepage&q&f=false topic in this ebook.

        You can also refer to "Signals and Slots documentation":http://qt-project.org/doc/qt-5.0/signalsandslots.html.

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          Technically they actually are defined: Moc adds code to all classes containing the Q_OBJECT macro, incl. some that implements the signals.

          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