×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Regular Contributor
    Join Date
    Feb 2009
    Location
    India
    Posts
    123

    NetworkReply problem

    hi,

    I have developed an application in which I hit the URL with some data and I get the reply from server.
    I have displayed reply in msg box.
    The problem is when I hit Url First time I get reply and displayed in Msg Box then I click ok,msg box terminates ..Now if again I hit url second time and get reply displayed in Msg box . I have to click two times on ok to terminate Msg Box.First reply is repeated and this continuies for no of Times I hit Url Previous Reply also get displayed and Msg Box Appears that may times.
    Problem is same code is working fine on WINCE(WINDOWS MOBILE),but creating above problem in SYMBAIN,can any one help me in this issue...

    Below is the Code:


    Code:
    void ABC:finishedSlot(QNetworkReply* reply)
    {
    
        if (reply->error() == QNetworkReply::NoError)
            {
                  QByteArray bytes = reply->readAll();
                  QString string(bytes); // string	 
    	      QString tristr= string.trimmed();	  
                  QMessageBox::information(this,"info",tristr);//display Reply
                 
             if(tristr.compare("false")==0)
    	   {
    	     QMessageBox::information(this,"Error","Please check your  credentials.");		
    			  
               }
    
    
           }
    
        else
            {
                 QMessageBox::information(this,"Error","Error Hitting URL.");
            }
       
     reply->deleteLater();
    }

    Regards,

    Vishal

  2. #2
    Nokia Developer Moderator
    Join Date
    Oct 2009
    Posts
    4,326

    Re: NetworkReply problem

    Can you show how do you connect signals?

  3. #3
    Regular Contributor
    Join Date
    Feb 2009
    Location
    India
    Posts
    123

    Re: NetworkReply problem

    Quote Originally Posted by divanov View Post
    Can you show how do you connect signals?
    Hi,
    Divanov thanks for reply below is the code:

    When I click on LoginButton below is signal:

    Code:
     connect(ui->pushLoginButton,SIGNAL(clicked()),this,SLOT(loginCheck()));
    Below is the code for LoginCheck Slot:

    Code:
    void ABC::loginCheck()
    {
         connect(nam,SIGNAL(finished(QNetworkReply*)),this,SLOT(finishedSlot(QNetworkReply*)));
          QUrl url("MyURL");
          QNetworkReply* reply  =  nam->get(QNetworkRequest(url));
    
       }
    }
    Code of finishedSlot(QNetworkReply*))); SLOT is in First Post

    Regards,

    Vishal

  4. #4
    Nokia Developer Moderator
    Join Date
    Oct 2009
    Posts
    4,326

    Re: NetworkReply problem

    Quote Originally Posted by vishalrocks101 View Post
    Code:
    void ABC::loginCheck()
    {
         connect(nam,SIGNAL(finished(QNetworkReply*)),this,SLOT(finishedSlot(QNetworkReply*)));
          QUrl url("MyURL");
          QNetworkReply* reply  =  nam->get(QNetworkRequest(url));
    
       }
    }
    As I expected, you connect finished signal to finishedSlot every time your press button. Instead it should be done once. when you create QNetworkAccessManager.

  5. #5
    Regular Contributor
    Join Date
    Feb 2009
    Location
    India
    Posts
    123

    Re: NetworkReply problem

    Quote Originally Posted by divanov View Post
    As I expected, you connect finished signal to finishedSlot every time your press button. Instead it should be done once. when you create QNetworkAccessManager.

    Hi,
    Divanov thank u very much .. Now My repetation problem of Msg Box Is solved

    I have placed the code:

    Code:
    connect(nam,SIGNAL(finished(QNetworkReply*)),this,SLOT(finishedSlot(QNetworkReply*)));   when I create QNetworkAccessManager.And removed it from loginCheck() SLOT
    One more thing is there any problem in getting "false" as string reply from PHP server.Because When I hit URL I am able to Display UID =1 as reply in MSG BOX. But When "false" is sent as reply I get Empty String I have debugged my application and seen it.

    When UID =2 is returned I get:
    Code:
    string = L"\r\n\r\n\t\t\t\t\r\n\t\t\t\t\r\n\t\t\tUID =2"
    When false is returned I get:

    Code:
    string = L"\r\n\r\n\t\t"
    Below is the URL:

    Code:
    http://124.247.237.173/push%20it/actionworkerlogin.php?txtemail=abc&txtpwd=aaa
    It gives false as reply.But I am getting empty string in :
    Code:
    QByteArray bytes = reply->readAll();
                  QString string(bytes); // string	 
    	      QString tristr= string.trimmed();	  
                  QMessageBox::information(this,"info",tristr);//display Reply
    Thanks once Agian

    Regards,

    Vishal

  6. #6
    Nokia Developer Moderator
    Join Date
    Oct 2009
    Posts
    4,326

    Re: NetworkReply problem

    Quote Originally Posted by vishalrocks101 View Post
    One more thing is there any problem in getting "false" as string reply from PHP server.Because When I hit URL I am able to Display UID =1 as reply in MSG BOX. But When "false" is sent as reply I get Empty String I have debugged my application and seen it.
    I've tried with test application from
    http://discussion.forum.nokia.com/fo...01&postcount=4
    and I'm getting "false".

  7. #7
    Regular Contributor
    Join Date
    Feb 2009
    Location
    India
    Posts
    123

    Re: NetworkReply problem

    Quote Originally Posted by divanov View Post
    I've tried with test application from
    http://discussion.forum.nokia.com/fo...01&postcount=4
    and I'm getting "false".
    Hi,
    Divanov thanks for reply,I have tried your code and it worked, then I looked at mine it was the same the problem was I have kept these two lines:

    Code:
       QImageReader imageReader(reply);
             QImage pic = imageReader.read();
    in void ABC::finishedslot(QNetworkReply* reply){} SLOT though it was not used then also it affected reply from server I dont know why.When I COMMENTED these two lines everything worked fine.


    Code:
    void ABC::finishedslot(QNetworkReply* reply)
    {
          
        if (reply->error() == QNetworkReply::NoError)
            {
            
    //         QImageReader imageReader(reply);//commented
    //         QImage pic = imageReader.read();//commented
               
               QByteArray bt = reply->readAll();
               QString st(bt); // string
               QString tristr= st.trimmed();	  
    	   QMessageBox::information(this,"info",tristr);
    }
    Thanks Once Again

    Regards,

    Vishal

  8. #8
    Nokia Developer Moderator
    Join Date
    Oct 2009
    Posts
    4,326

    Re: NetworkReply problem

    Quote Originally Posted by vishalrocks101 View Post
    in void ABC::finishedslot(QNetworkReply* reply){} SLOT though it was not used then also it affected reply from server I dont know why.When I COMMENTED these two lines everything worked fine.
    Because QImageReader reads all the data from QIODevice (QNetworkReply) setting marker to the end of the device. Any consequential attempt to read data will return an empty result. You need to reset QIODevice to be able to read data once again:
    http://doc.trolltech.com/4.6/qiodevice.html#reset
    or
    http://doc.trolltech.com/4.6/qiodevice.html#seek

  9. #9
    Regular Contributor
    Join Date
    Feb 2009
    Location
    India
    Posts
    123

    Re: NetworkReply problem

    Quote Originally Posted by divanov View Post
    Because QImageReader reads all the data from QIODevice (QNetworkReply) setting marker to the end of the device. Any consequential attempt to read data will return an empty result. You need to reset QIODevice to be able to read data once again:
    http://doc.trolltech.com/4.6/qiodevice.html#reset
    or
    http://doc.trolltech.com/4.6/qiodevice.html#seek
    Hi,
    Divanov,I have checked the link u provided,it is helpful,thank u


    Regards,

    Vishal

Similar Threads

  1. STLPort namespace issue
    By yickhong in forum Open C/C++
    Replies: 0
    Last Post: 2009-04-09, 08:54
  2. SyncML link problem
    By samuel_ in forum Symbian C++
    Replies: 4
    Last Post: 2009-03-27, 08:02
  3. Problem with eglSwapBuffers and heap corruption
    By greatape in forum Symbian Media (Closed)
    Replies: 2
    Last Post: 2007-05-24, 03:35
  4. netcards - Problem with opening adapter
    By kernj in forum Symbian Tools & SDKs
    Replies: 5
    Last Post: 2007-01-10, 08:56
  5. Problem: S60 SDK for CW in PC with .NET
    By anttij in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 1
    Last Post: 2005-02-28, 11:36

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •