connection error in QObject::connect()



  • how do i make syntax highlighting for c++ when creating thread in this forum?

    no matching function for call to 'MainWindow::connect(ServerManager*, const char*, MainWindow*, const char*)'
    QObject::connect(&server,SIGNAL(display()),this,SLOT(display()));

    why i keep getting this error.

    class MainWindow
    {
    ServerManager server;
    MainWindow()
    {
    QObject::connect(&server,SIGNAL(display()),this,SLOT(display()));
    }
    private slots:
    void display();
    };

    void MainWindow::display()
    {
    std::string m;
    sf::Int32 i;
    server.getPacket() >> m >> i;
    if ( i == 0 )
    {
    ui->clientList->addItem(QString::fromStdString("m"));
    }
    }

    class ServerManager
    {
    public:
    void test();
    signals:
    void display();
    }

    void ServerManager::test()
    {
    emit display();
    }



  • Both your classes need to inherit from QObject for the signal/slot mechanism to work.

    Code blocks are either preceded by 4 spaces (good for one liners):

    int variable;
    

    or they can be enclosed by `` ` (triple back ticks, good for inline elements and longer blocks):

    #include <iostream>
    
    int main (int argc, char * argv[]) {
       std::cout << "Hello, World!\n";
    }
    

    Google Markdown syntax for some more markup details.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.