Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6730575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:25:29+00:00 2026-05-26T10:25:29+00:00

I would like to connect to a listening server and transmit some data. I

  • 0

I would like to connect to a listening server and transmit some data. I looked at the examples available but they seem to have extra functions that do not seem very helpful to me (i.e. connect, fortune, etc.). This is the code I have so far:

QTcpSocket t;
t.connectToHost("127.0.0.1", 9000);

Assuming the server is listening and robust, what do I need to implement to send a data variable with datatype QByteArray?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:25:30+00:00Added an answer on May 26, 2026 at 10:25 am

    very simple with QTcpSocket. Begin as you did…

    void MainWindow::connectTcp()
    {
        QByteArray data; // <-- fill with data
    
        _pSocket = new QTcpSocket( this ); // <-- needs to be a member variable: QTcpSocket * _pSocket;
        connect( _pSocket, SIGNAL(readyRead()), this, SLOT(readTcpData()) );
    
        _pSocket->connectToHost("127.0.0.1", 9000);
        if( _pSocket->waitForConnected() ) {
            _pSocket->write( data );
        }
    }
    
    void MainWindow::readTcpData()
    {
        QByteArray data = pSocket->readAll();
    }
    

    Be aware, though, that for reading from the TcpSocket you may receive the data in more than one transmission, ie. when the server send you the string "123456" you may receive "123" and "456". It is your responsibility to check whether the transmission is complete. Unfortunately, this almost always results in your class being stateful: the class has to remember what transmission it is expecting, whether it has started already and if it’s complete. So far, I haven’t figured out an elegant way around that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an IFrame app, and I would like to use some Connect features
I have an AIR application and would like to connect to an LDAP server
I would like to connect to a FTP from Java. I have done this:
I have a business object that I would like to connect to my UI
I would like to connect to a server on tcp/ip to the port 65000
I would like to connect my application via the internet to a server which
I would like to connect to a clustered Oracle database described by this TNS:
I would like to connect to java process started by eclipse using a command
I would like to connect to a DB2 database, specifically an iSeries version, using
I would like to connect to those applications which provided OAuth API (such as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.