Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 4

Qt-interest Archive, April 2007
Client program using QSocket


Message 1 in thread

hi,


I am using QSocket to connect to server. I have a client program using
QSocket. i am connecting to server in my slot as follows,

void mainForm::connect()
{
mysock=new QSocket(NULL);
  mysock->connectToHost("192.168.100.128",3535);
    connect(mysock, SIGNAL( connected() ),
             this, SLOT( sockConnect() ) );
    connect(mysock, SIGNAL(readyRead()),this, SLOT(sockReadyRead()));
    connect(mysock, SIGNAL( hostFound() ),
             this, SLOT( sockHostFound() ) );
    connect(mysock, SIGNAL( connectionClosed() ),
             this, SLOT( sockClose() ) );
    connect(mysock, SIGNAL( error( int ) ),
             this, SLOT( sockError( int ) ) );


 }


As server always not ready, i am connecting to server also in thread  when
 socket error comes(connFlag=0 when socket error, and connFlag=1 when
connected succussfully) as follows,



void* connFun(void *arg)
{
    while(1)
    {

        if(connFlag==0)
        {
                      mysock->connectToHost(appsettings.nServerIP,atol(appsettings.nServerPort));
        }
        sleep(10);
    }


}




If server is not ready, i always get socket error from sockError slot. but
after some time i get the follwing error:



QSocketNotifier: multiple socket notifier for same socket 14




As i searched, it says, if connecting in succession to socket it comes.



Can anybody tell me how to resolve this problem As i want it in thread.



Thanks and Regards,

Niranjan.

--
 [ signature omitted ] 

Message 2 in thread

Hi,

> I am using QSocket to connect to server. I have a client program using
> QSocket. i am connecting to server in my slot as follows,

Which version of Qt is this? On which platform?

> [...]
> As server always not ready, i am connecting to server also in thread  when
>  socket error comes(connFlag=0 when socket error, and connFlag=1 when
> connected succussfully) as follows,

I'm afraid I can't understand what is meant by "server always not ready". Is 
there any error message? How do you check that?

Since you're using QSocket, you must be using Qt 3. Speaking of threads, I 
think the following parts of the documentation may explain any errors you're 
getting when using QSocket in secondary threads.

	http://doc.trolltech.com/3.3/qsocket.html#details
		Warning: QSocket is not suitable for use in threads.
		If you need to uses sockets in threads use the lower-level
		QSocketDevice class.

	http://doc.trolltech.com/3.3/threads.html#6
		None of the QObject based classes included in the
		Qt library are reentrant. This includes [...] all
		networking classes (e.g. QSocket, QDns).

--
 [ signature omitted ] 

Message 3 in thread

hi,

I am using qt-3.1 on Fedora core 3. Server is not ready means, server
application is not on. only client appplication is ready, when connecting
to server , (as server application is not on) i get socket error.   As i
want to check wheather server on or off in succession, i need to connect
it in thread.


So, what's the solution


Thanks and Regards,
Niranjan


> Hi,
>
>> I am using QSocket to connect to server. I have a client program using
>> QSocket. i am connecting to server in my slot as follows,
>
> Which version of Qt is this? On which platform?
>
>> [...]
>> As server always not ready, i am connecting to server also in thread
>> when
>>  socket error comes(connFlag=0 when socket error, and connFlag=1 when
>> connected succussfully) as follows,
>
> I'm afraid I can't understand what is meant by "server always not ready".
> Is
> there any error message? How do you check that?
>
> Since you're using QSocket, you must be using Qt 3. Speaking of threads, I
> think the following parts of the documentation may explain any errors
> you're
> getting when using QSocket in secondary threads.
>
> 	http://doc.trolltech.com/3.3/qsocket.html#details
> 		Warning: QSocket is not suitable for use in threads.
> 		If you need to uses sockets in threads use the lower-level
> 		QSocketDevice class.
>
> 	http://doc.trolltech.com/3.3/threads.html#6
> 		None of the QObject based classes included in the
> 		Qt library are reentrant. This includes [...] all
> 		networking classes (e.g. QSocket, QDns).
>
> --
> Dimitri
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
>

--
 [ signature omitted ] 

Message 4 in thread

Hi,

> I am using qt-3.1 on Fedora core 3. Server is not ready means, server
> application is not on. only client appplication is ready, when connecting
> to server , (as server application is not on) i get socket error.   As i
> want to check wheather server on or off in succession, i need to connect
> it in thread.

The problem is, you cannot use QSocket in a secondary thread. But why do you 
think you need a thread?

> So, what's the solution

Are you indeed using QSocket in a thread? The solution is to modify your code:
* either use QSocket from the main thread only,
* or use QSocketDevice instead.

--
 [ signature omitted ] 

Message 5 in thread

Hi,


my source code like as...


void mainForm::focusInEvent(QFocusEvent *e)
{
   mysock=new QSocket(NULL);
   mysock->connectToHost("192.168.100.128",3535);
   connect(mysock, SIGNAL( connected() ),
             this, SLOT( sockConnect() ) );
   connect(mysock, SIGNAL(readyRead()),this, SLOT(sockReadyRead()));
   connect(mysock, SIGNAL( hostFound() ),
             this, SLOT( sockHostFound() ) );
   connect(mysock, SIGNAL( connectionClosed() ),
             this, SLOT( sockClose() ) );
   connect(mysock, SIGNAL( error( int ) ),
             this, SLOT( sockError( int ) ) );


}

void mainForm::sockError(int a)
{
     puts("Socket Error");
}

void mainForm::sockClose()
{
     puts("Socket Closed");
}


void mainForm::sockHostFound()
{
     puts("Host Found");
}

void mainForm::sockReadyRead()
{
     puts("Ready Read");
}

void mainForm::connected()
{
     puts("Connected Successfully");
}



As from above code, when server application not ready, client application
will get socket error from sockError(int a) slot.
 From some time, when i start the server application, how i get in
connected slot, if socket is not in thread.


I need to check frequently wheather server is ready or not.How do i do
this without thread??????



Thnaks and Regards,
Niranjan



> Hi,
>
>> I am using qt-3.1 on Fedora core 3. Server is not ready means, server
>> application is not on. only client appplication is ready, when
>> connecting
>> to server , (as server application is not on) i get socket error.   As i
>> want to check wheather server on or off in succession, i need to connect
>> it in thread.
>
> The problem is, you cannot use QSocket in a secondary thread. But why do
> you
> think you need a thread?
>
>> So, what's the solution
>
> Are you indeed using QSocket in a thread? The solution is to modify your
> code:
> * either use QSocket from the main thread only,
> * or use QSocketDevice instead.
>
> --
> Dimitri
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
>

--
 [ signature omitted ] 

Message 6 in thread

Hi,

> my source code like as...
> [...]
> As from above code, when server application not ready, client application
> will get socket error from sockError(int a) slot.

I'm not sure what you mean exactly by "server application not ready". If the 
server application is not listening, you won't be able to connect. Is that 
your concern?

>  From some time, when i start the server application, how i get in
> connected slot, if socket is not in thread.

The sockConnect() slot will be called when the connected() signal is emitted:
	http://doc.trolltech.com/3.3/qsocket.html#connected
	void QSocket::connected()
	This signal is emitted after connectToHost() has been called
	and a connection has been successfully established.

> I need to check frequently wheather server is ready or not.How do i do
> this without thread??????

I'm not sure what you need to check from a different thread. As far as I can 
understand you just have to wait for the connected() signal.

If the connected() signal is not emitted, that's because the server could not 
be reached. In that case, I seem to recall the error() signal is emitted after 
the system times out:
	http://doc.trolltech.com/3.3/qsocket.html#error
	This signal is emitted after an error occurred. The parameter
	is the Error value.
where the argument of the signal can be one of:
	http://doc.trolltech.com/3.3/qsocket.html#Error-enum
	QSocket::Error
	This enum specifies the possible errors:
	* QSocket::ErrConnectionRefused - if the connection was refused
	* QSocket::ErrHostNotFound - if the host was not found
	* QSocket::ErrSocketRead - if a read from the socket failed

--
 [ signature omitted ] 

Message 7 in thread

hi,

Yes, u right, when server application is not listening, i won;t be able to
connect.    but suppose after some time my server application is on(client
is already running). i can't get connected signal. That's why, i need to
connect to server in thread.(For Checking when server is on)


How to do it whithout thread????
Thanks and Regards,
Niranjan.



> Hi,
>
>> my source code like as...
>> [...]
>> As from above code, when server application not ready, client
>> application
>> will get socket error from sockError(int a) slot.
>
> I'm not sure what you mean exactly by "server application not ready". If
> the
> server application is not listening, you won't be able to connect. Is that
> your concern?
>
>>  From some time, when i start the server application, how i get in
>> connected slot, if socket is not in thread.
>
> The sockConnect() slot will be called when the connected() signal is
> emitted:
> 	http://doc.trolltech.com/3.3/qsocket.html#connected
> 	void QSocket::connected()
> 	This signal is emitted after connectToHost() has been called
> 	and a connection has been successfully established.
>
>> I need to check frequently wheather server is ready or not.How do i do
>> this without thread??????
>
> I'm not sure what you need to check from a different thread. As far as I
> can
> understand you just have to wait for the connected() signal.
>
> If the connected() signal is not emitted, that's because the server could
> not
> be reached. In that case, I seem to recall the error() signal is emitted
> after
> the system times out:
> 	http://doc.trolltech.com/3.3/qsocket.html#error
> 	This signal is emitted after an error occurred. The parameter
> 	is the Error value.
> where the argument of the signal can be one of:
> 	http://doc.trolltech.com/3.3/qsocket.html#Error-enum
> 	QSocket::Error
> 	This enum specifies the possible errors:
> 	* QSocket::ErrConnectionRefused - if the connection was refused
> 	* QSocket::ErrHostNotFound - if the host was not found
> 	* QSocket::ErrSocketRead - if a read from the socket failed
>
> --
> Dimitri
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
>

--
 [ signature omitted ] 

Message 8 in thread

On 4/18/07, niranjank@xxxxxxxxxxxx <niranjank@xxxxxxxxxxxx> wrote:
> hi,
>
> Yes, u right, when server application is not listening, i won;t be able to
> connect.    but suppose after some time my server application is on(client
> is already running). i can't get connected signal. That's why, i need to
> connect to server in thread.(For Checking when server is on)
>
>
> How to do it whithout thread????

You can create an alarm to schedule a new connection attempt at some
point in the future after you've noticed a failure to connect or a
close.

-K

--
 [ signature omitted ] 

Message 9 in thread

hi,

Thank you for your response. I hope, my problem is solved now. Tnank your
for your reply.

Now my proble is...


I want to set jpg images on qt-3.1 form one after another means,

for example...

i=0;
j=0;
i=j+1;

fm->setPalleteBackgroundPixmap((QPixmap)"aa.jpg");
wait for 5 seconds.

i=i+1;
j=j+1;

fm->setPalleteBackgroundPixmap((QPixmap)"bb.jpg");
wait for 5 seconds.

i=i+1;
j=j+1;

fm->setPalleteBackgroundPixmap((QPixmap)"cc.jpg");

i=i+1;
j=j+1;




When i used sleep or usleep, it shows aa.jpg and then dirctly it  cc.jpg and
  discards bb.jpg.

I also used QTimer::singleshot and

QApplication::eventLoop()->processEvents(QEventLoop::AllEvents,100);
sleep(6);


 but, sometimes it blocks the application.


What should i do to show images in sequence after some interval.




Thanks and Regards,
Niranjan.
















> On 4/18/07, niranjank@xxxxxxxxxxxx <niranjank@xxxxxxxxxxxx> wrote:
>> hi,
>>
>> Yes, u right, when server application is not listening, i won;t be able
>> to
>> connect.    but suppose after some time my server application is
>> on(client
>> is already running). i can't get connected signal. That's why, i need to
>> connect to server in thread.(For Checking when server is on)
>>
>>
>> How to do it whithout thread????
>
> You can create an alarm to schedule a new connection attempt at some
> point in the future after you've noticed a failure to connect or a
> close.
>
> -K
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
>

--
 [ signature omitted ] 

Message 10 in thread

Am Donnerstag, 19. April 2007 08:50 schrieb niranjank@xxxxxxxxxxxx:
> hi,
>
> Thank you for your response. I hope, my problem is solved now. Tnank your
> for your reply.
>
> Now my proble is...
>
>
> I want to set jpg images on qt-3.1 form one after another means,
>
> for example...
>
> i=0;
> j=0;
> i=j+1;
>
> fm->setPalleteBackgroundPixmap((QPixmap)"aa.jpg");
> wait for 5 seconds.
>
> i=i+1;
> j=j+1;
>
> fm->setPalleteBackgroundPixmap((QPixmap)"bb.jpg");
> wait for 5 seconds.
>
> i=i+1;
> j=j+1;
>
> fm->setPalleteBackgroundPixmap((QPixmap)"cc.jpg");
>
> i=i+1;
> j=j+1;
>
>
>
>
> When i used sleep or usleep, it shows aa.jpg and then dirctly it  cc.jpg
> and discards bb.jpg.
>
> I also used QTimer::singleshot and


I think you should do some more experiments with QTimer (not only singleshot) 
and implement the above picture change function as the timer callback slot.



>
> QApplication::eventLoop()->processEvents(QEventLoop::AllEvents,100);
> sleep(6);
>

Don't use sleep in interactive applications.  You should better sleep within 
the application loop and react with a function on some sleep condition:

// no sleep:
QTimer::singleShot(6000, yourObject /* might be |this| */, 	 
                      timeoutOperationSlot );


Simply step out into your application loop without processEvents (if 
possible).

After 6 seconds you can check if something has happened in 
timeoutOperationSlot or restart the timer or whatever.


>
>  but, sometimes it blocks the application.
>
>
> What should i do to show images in sequence after some interval.
>
>
>
>
> Thanks and Regards,
> Niranjan.
>
> > On 4/18/07, niranjank@xxxxxxxxxxxx <niranjank@xxxxxxxxxxxx> wrote:
> >> hi,
> >>
> >> Yes, u right, when server application is not listening, i won;t be able
> >> to
> >> connect.    but suppose after some time my server application is
> >> on(client
> >> is already running). i can't get connected signal. That's why, i need to
> >> connect to server in thread.(For Checking when server is on)
> >>
> >>
> >> How to do it whithout thread????
> >
> > You can create an alarm to schedule a new connection attempt at some
> > point in the future after you've noticed a failure to connect or a
> > close.
> >
> > -K
> >
> > --
> > To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> > "unsubscribe" in the subject or the body.
> > List archive and information: http://lists.trolltech.com/qt-interest/
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body. List archive and information:
> http://lists.trolltech.com/qt-interest/

-- 
 [ signature omitted ] 

Message 11 in thread

Hi,

By the way, this had already been posted once:
	http://lists.trolltech.com/qt-interest/2007-04/thread00607-0.html
Please don't the same question multiple times.

If no one answers, that's probably because:
* no one knows the answer,
* no one can find an answer in a reasonable time frame,
* no one is interested,
* no one has found the time to answer yet, but intends to if no one else 
answers in the meantime,
* ...

--
 [ signature omitted ]