Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Signal and slots
Forum Updated to NodeBB v4.3 + New Features

Signal and slots

Scheduled Pinned Locked Moved QML and Qt Quick
9 Posts 3 Posters 2.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.
  • F Offline
    F Offline
    fekda778
    wrote on last edited by
    #1

    Hi,
    I have been using SIGNAL-SLOT for a long time.

    But I have one connection which doesn’t want work.

    I emitted the signal, but nothing happened.

    My code:

    @connect(stations, SIGNAL(send(int,int,int)), cServer, SLOT(writeToCiensAll(int, int ,int) ));@

    cServer has its own thread using moveToThread(&Thread function);

    According to the “connect” I have two objects:

    @
    //stations object header
    signals:
    void send(int, int ,int);@

    @
    //cServer object:
    //in header:
    public slots:
    void writeToCiensAll(int, int, int );@

    @
    //in cpp:
    void Server::writeToCiensAll(int station, int state, int size){
    qDebug() << "message is sent";
    //code here
    }@

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      What does the connect call return? Do you get any output on the console/debugging stream?

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fekda778
        wrote on last edited by
        #3

        And the emit
        @ emit send(12,1,2);@

        1 Reply Last reply
        0
        • F Offline
          F Offline
          fekda778
          wrote on last edited by
          #4

          the return value of connect(…) is true.

          I also used Debug, but I didn’t know what I should have done. Because there were not any value to check.
          I went step by step.
          When I emit the signal this function is used only:
          (according to debug step by step function)
          @void Stations::send(int _t1, int _t2, int _t3)
          {
          void _a[] = { 0, const_cast<void>(reinterpret_cast<const void*>(&_t1)), const_cast<void*>(reinterpret_cast<const void*>(&_t2)), const_cast<void*>(reinterpret_cast<const void*>(&_t3)) };
          QMetaObject::activate(this, &staticMetaObject, 1, _a);
          }
          @

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            Are you sure that you're not somehow re-creating the cServer instance or something like that after the connect call?

            1 Reply Last reply
            0
            • L Offline
              L Offline
              lgeyer
              wrote on last edited by
              #6

              Does the server thread have a spinning event loop (that is did you call start() or at least exec() if you have reimplemented run())?

              You won't be able to receive signals if you haven't.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                [quote author="Lukas Geyer" date="1360845486"]Does the server thread have a spinning event loop (that is did you call start() or at least exec() if you have reimplemented run())?

                You won't be able to receive signals if you haven't.[/quote]

                Excellent point! cServer does need a running eventloop of course...

                1 Reply Last reply
                0
                • F Offline
                  F Offline
                  fekda778
                  wrote on last edited by
                  #8

                  cServer is a „special class”.
                  The new thread was made as a mentioned above. But I had problem with clients. I used the old c style to make new thread as a function. (pthread). But this is a class and the function is a member function.
                  I find a solution for this problem. I used a static member function to call the „new thread function.”
                  Can be any connection between this solution and the signal?

                  The server is waiting for client.

                  connect( … ) is the last line in the constructor of the class. I mean the class that is used to store the above objects.

                  1 Reply Last reply
                  0
                  • F Offline
                    F Offline
                    fekda778
                    wrote on last edited by
                    #9

                    I have solved this problem using function pointer. It is not the best solution but it works finally.

                    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