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. How to use a SIGNAL that has QVector<QTcpSocket *> as it's argument in connect()?

How to use a SIGNAL that has QVector<QTcpSocket *> as it's argument in connect()?

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 3 Posters 2.0k Views 2 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.
  • B Offline
    B Offline
    Bamshad
    wrote on last edited by
    #1

    Hello,

    I work on a server-client project. In the server side I make the list of current clients with

    QVector<QTcpSocket *> mClients.
    mClients.push_back(recievedSocket);

    I want to send the mClients to the clients (threads). So, I decided to make a signal and connect it to the proper slot. However, I face with this error:

    "QObject::connect: No such signal serverSocketClass::listOfClients(mClients)"

    although I have declared the signal.

    Should I use QMetaType Class to register the QVector<QTcpSocket *>?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Did you add the QOBJECT macro?
      It sounds more like something else than lack of registering the type.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Bamshad
        wrote on last edited by
        #3

        Yes, I have added the Q_OBJECT and I made another signal without any argument and it worked. So, It looks the problem is because of the SIGNAL argument which is a Vector<QTcpSocket *>. I tried to register it with qRegisterMetaType<QVector<QTcpSocket *>>(); but it does not work. Maybe I made some mistakes in case of registration.

        mrjjM 1 Reply Last reply
        0
        • B Bamshad

          Yes, I have added the Q_OBJECT and I made another signal without any argument and it worked. So, It looks the problem is because of the SIGNAL argument which is a Vector<QTcpSocket *>. I tried to register it with qRegisterMetaType<QVector<QTcpSocket *>>(); but it does not work. Maybe I made some mistakes in case of registration.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          @Bamshad
          Hi
          In which way. "Dont work" ?
          Normally it would complain if type needs registering.

          I did

          class MainWindow : public QMainWindow
          {
              Q_OBJECT
          private slots:
              void GetIT( QVector<QTcpSocket *> );
          signals:
              void sendIT( QVector<QTcpSocket *> );
          

          connect( this, &MainWindow::sendIT, this, &MainWindow::GetIT );
          QVector<QTcpSocket *> test;
          emit sendIT(test);

          and it just compiled.

          Did you give it the variable name and not the type in declaration something like that?

          1 Reply Last reply
          1
          • B Offline
            B Offline
            Bamshad
            wrote on last edited by
            #5

            It is a server-client project and the signal emits after first client is arrived. In this situation, is it considered as a "queued signal"? Because, in the documentation of QMetaType it is mentioned that:

            "The class is used as a helper to marshall types in QVariant and in queued signals and slots connections".

            That is why I think maybe I need to use QMetaType class. However, I should mention that other signals that are related to the sockets like clientDisconnected() (which also will be used later) work fine. So, I am so confused. I do not now if it is a queued signal.

            mrjjM 1 Reply Last reply
            0
            • B Bamshad

              It is a server-client project and the signal emits after first client is arrived. In this situation, is it considered as a "queued signal"? Because, in the documentation of QMetaType it is mentioned that:

              "The class is used as a helper to marshall types in QVariant and in queued signals and slots connections".

              That is why I think maybe I need to use QMetaType class. However, I should mention that other signals that are related to the sockets like clientDisconnected() (which also will be used later) work fine. So, I am so confused. I do not now if it is a queued signal.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              @Bamshad
              Hi
              The connect type is Auto pr default.
              So should not be that.
              Also here it just compiled and worked so i think we are looking at something else.
              Could you try to add the signal to the serverSocketClass again and then
              completely delete the build folder and rebuild all ?

              1 Reply Last reply
              0
              • B Offline
                B Offline
                Bamshad
                wrote on last edited by
                #7

                connect( this, &MainWindow::sendIT, this, &MainWindow::GetIT );

                In this line, have you passed the argument to the signal?

                in my case it is like this:

                connect(this,SIGNAL(listOfClients(mClients)),this,SLOT(setListofClients(QVector<QTcpSocket *>)));

                Is it correct syntax?

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Hi,

                  No that syntax is wrong. connect only connects two methods. You can't pass parameters at that time. It's when you want the to emit the signal that you pass the value needed.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  2
                  • mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by mrjj
                    #9

                    Hi
                    mClients is only used in the emit.
                    like
                    connect( this, &MainWindow::sendIT, this, &MainWindow::GetIT );
                    QVector<QTcpSocket *> mClients;
                    emit sendIT(mClients);

                    B 1 Reply Last reply
                    2
                    • mrjjM mrjj

                      Hi
                      mClients is only used in the emit.
                      like
                      connect( this, &MainWindow::sendIT, this, &MainWindow::GetIT );
                      QVector<QTcpSocket *> mClients;
                      emit sendIT(mClients);

                      B Offline
                      B Offline
                      Bamshad
                      wrote on last edited by
                      #10

                      @mrjj and @SGaist Thank you very much.

                      Yes, it was my syntax mistake. So I changed

                      connect(this,SIGNAL(listOfClients(mClients)),this,SLOT(setListofClients(QVector<QTcpSocket *>)));

                      To

                      connect(this,&serverSocketClass::listOfClients,thread,&clientSocketClass::setListofClients);

                      emit listOfClients(mClients);

                      and now it works!!

                      I wanted to read QMetaType Class that was not related to the problem.

                      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