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. I need help ; the connect() is not working.
Forum Updated to NodeBB v4.3 + New Features

I need help ; the connect() is not working.

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 563 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.
  • B Offline
    B Offline
    Bit Asterisk
    wrote on last edited by
    #1

    Greetings from Nepal.

    We're building a desktop application using Qt Creator. In short, this application uses QTcpSocket and QTcpServer and the socket is multithreaded (using QThread) i.e. different users can connect at a time. MainWindow, MyServer and MyThread are different c++ class.

    When a "Host "push button is pressed (mainwindow.cpp), the server is started (myserver.cpp). When a user is connected to the server, the server starts new thread for the connected user (mythread.cpp). When the user sends char/string, the Qthread class receives the char/string. But we want to pass the string to MainWindow and display using QLineEdit. Todo so, we use a signals and slot but it's not working.

    // mainwindow.cpp
    myThread = new MyThread(); // MyThread is a c++ class
    connect(myThread,SIGNAL(chatText(QString)),this,SLOT(updateChat(QString)));
    
    ...
    ...
    ..
    void MainWindow::updateChat(QString str)
    {
    ui->plainTextEdit_chatInterface->setPlainText(str);
    }
    

    mythread.cpp

    //readyRead()
    
    void MyThread::readyRead()
    {
      data=socket->readAll();
      emit chatText(data);
    }
    
    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Can you confirm readyRead method is called ? Do you see any error like connect issue on application log window or logs ?

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      4
      • B Offline
        B Offline
        Bit Asterisk
        wrote on last edited by
        #3

        yeah, the readyRead() method is called when a user send something, qDebug()<<data; is showing the char/string. But mainwindow is not receiving the string.

        thank you for reply.

        1 Reply Last reply
        0
        • B Offline
          B Offline
          Bit Asterisk
          wrote on last edited by
          #4

          Thank you. I solved 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