You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Friday, May 11th 2012, 10:32am

signal slot in console

hi

i want to write a server chat program in qtconsole
i have not problem with gui program
my problem is in console

i send a data with another program to port 1212
but this programm (below) not get data from 1212
where i have a mistake????
thank you very much

main.cpp

Source code

1
2
3
4
5
6
7
8
9
#include "server.h"
#include 

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    server *t = new server();
    return a.exec();
}



server.h

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#ifndef SERVER_H
#define SERVER_H

#include 
#include 

class server : public QObject
{
    Q_OBJECT
    public:
        explicit server(QObject *parent = 0);

    private:
        QUdpSocket *udpSocket;

    public slots:
        void processPendingDatagrams();
};

#endif // SERVE_H



server.cpp

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "server.h"

server::server(QObject *parent) :
    QObject(parent)
{
    udpSocket = new QUdpSocket();
    udpSocket->bind(1212);
    connect(udpSocket, SIGNAL(readyRead()) , this ,SLOT(processPendingDatagrams()));

}

void server::processPendingDatagrams()
{
    while(udpSocket->hasPendingDatagrams())
    {
        QByteArray temp;
        temp.resize(udpSocket->pendingDatagramSize());
        udpSocket->readDatagram(temp.data(),temp.size());
        QString text = QString::fromUtf8(temp);
    }
    udpSocket->writeDatagram("userName exist",QHostAddress("127.0.0.1"),1818);
}

This post has been edited 1 times, last edit by "csqhossein" (May 14th 2012, 7:47pm)


2

Saturday, May 12th 2012, 6:32am

please ??????????????????????!!!!!!!!!!!!

3

Saturday, May 12th 2012, 9:42pm

too rouhe tak taketoun ...