Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. [SOLVED] Help using SLOTs
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Help using SLOTs

Scheduled Pinned Locked Moved C++ Gurus
5 Posts 3 Posters 2.5k 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.
  • D Offline
    D Offline
    drobe011
    wrote on last edited by
    #1

    I cannot for the life of me, get my slot to be connected/recognized. Any help would be appreciated.

    The following class just connects and polls a simple telnet server running on port 8090. The connection and reading work fine. (I was originally using UDP,hence the weird file/class names).

    xpudp.h
    @#ifndef XPUDP_H
    #define XPUDP_H

    #include <QtNetwork/QTcpSocket>

    class XpUDP : public QObject
    {
    public:
    XpUDP(char * host = "localhost", int port = 8090);
    bool getIsConnected();
    QTcpSocket * getTelnet();
    bool connectTelnet();
    private:
    QTcpSocket * telnet;
    void initSocket();
    bool isConnected;
    char * myhost;
    int myport;
    private slots:
    void readPort();
    };

    #endif // XPUDP_H
    @

    xpudp.cpp
    @#include "xpudp.h"
    #include <iostream>
    #include <QtNetwork>

    XpUDP::XpUDP(char * host, int port)
    {
    myhost = host;
    myport = port;
    initSocket();
    }

    void XpUDP::initSocket()
    {
    telnet = new QTcpSocket;
    isConnected = connectTelnet();
    }

    QTcpSocket * XpUDP::getTelnet() /* Just have this for testing purposes */
    {
    return telnet;
    }

    bool XpUDP::getIsConnected()
    {
    return isConnected;
    }

    void XpUDP::readPort() // This SLOT not being recognized
    {
    int read_ret = 0;
    char buf[512];
    memset(buf, 0, 512);

    read_ret =  telnet->read(buf, 512);
    //printf("recived[%i] '%s'\n", read_ret, buf);
    std::cout << buf;
    memset(buf, 0, 512);
    

    }

    bool XpUDP::connectTelnet()
    {
    telnet->connectToHost(myhost, myport);
    if (telnet->waitForConnected(5000) == false)
    {
    return false;
    }
    else
    {
    connect(telnet, SIGNAL(readyRead()),
    this, SLOT(readPort())); /* I get QObject::connect: No such slot QObject::readPort() */
    return true;
    }
    }
    @
    During runtime, if a connection is made I get this message in the console: QObject::connect: No such slot QObject::readPort(). Any help getting my slot reacting to the signal would be appreciated, or if events would be the way to go.

    I have Qt 4.8.2, using Qt Creator 2.4.1, qmake 2.01a, g++ 4.7.0, on a Linux Fedora 17 x86_64 system.

    FYI if it helps, I am making a moving map (MarbleMap) and instrument cluster for a flight sim.

    Thanks, Dave

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

      You forgot to include the Q_OBJECT macro in your class declaration.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mlong
        wrote on last edited by
        #3

        Be sure and add the Q_OBJECT macro when you define your class.

        [Edit: Andre beat me to it.]

        Software Engineer
        My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          drobe011
          wrote on last edited by
          #4

          Awesome, works now.

          After I added Q_OBJECT, did a make clean and rebuilt; I got an undefined reference to vtable for xxx. After running qmake -r all is good.

          Thanks, Dave

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mlong
            wrote on last edited by
            #5

            Be sure and edit your initial post to add [Solved] to the title. Thanks!

            Software Engineer
            My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

            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