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 8280447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:40:54+00:00 2026-06-08T09:40:54+00:00

I am a new to the QT programming. my server/client codes are quite simple

  • 0

I am a new to the QT programming. my server/client codes are quite simple but they are not working…….

pls have a look to find problems in my codes, thanks.

SERVER:

int main(int argc, char** argv)
{
//  QApplication app(argc, argv);
//      Server server;
        QTcpSocket *client_sock =  NULL;
        QTcpServer server;
        server.listen(QHostAddress::Any,8888);
        char buff[100];

    while(1)
    {
            if(server.hasPendingConnections())
            {
                    client_sock = server.nextPendingConnection();
            }
            if(client_sock)
            {
                    qint64 n_rtn;
                    n_rtn = client_sock->bytesAvailable();
                    client_sock->readLine(buff,n_rtn);
                    std::cout<<buff;
            }
    }
//  return app.exec();
}

CLIENT:

int main(int argc, char** argv)
{
//  QApplication app(argc, argv);
  QTcpSocket client;
  QHostAddress addr("127.0.0.1");
  client.connectToHost(addr,8888);

  if(client.isWritable())
  {
        client.write("Hello World!\n");
  }

  client.close();

//  return app.exec();
}

Thanks

  • 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-06-08T09:40:56+00:00Added an answer on June 8, 2026 at 9:40 am

    Without a QApplication or a QCoreApplication and an app.exec() nothing will work. This is what runs the event loop which handles all the keyboard/mouse/network events.

    Take a look at the chat and fortune cookie network server examples to see how to do this – it’s almost as simple as the code you have written

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

Sidebar

Related Questions

i have written simple client server socket programming code as follow MyServer.java import java.io.DataInputStream;
I'm programming a server-client application and I have a problem when transferring to the
Hello Dear StackOverflowers, I am new to web programming and finding the server-client mixture
I am rather new to socket programming but here goes nothing. I have been
I am new to both C# and to client-server programming. Right now, for class,
Ruby on Rails has become a new competitive face in the server programming industry,
Totally new to programming so kindly excuse the silly question. I have this URL
I am new to network programming, and have been learning this by writing small
I am using socket programming in vb.net to create a server client remoting application.
I need to develop a client server system where I can have multiple clients

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.