×

Discussion Board

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

    NetworkReply (finished Slot) with Position update Slot

    Hi,

    I have done an application in which I get Latitude and Longitude,then based on this I am checking for some condition and hitting a URL ,now the problem is I am able to Hit URL as I can see Entry on Server, but the SLOT
    void LatLong::finishedslot(QNetworkReply* reply)
    is not called So I am unable to get Reply.
    I don't know what is the problem,can we use Position Update Slot and FinishedSlot together??

    Below is the Code for PositionUpdate Slot,, interval is Kept for 10 Secs:

    Code:
    void LatLong::positionUpdated(const QGeoPositionInfo &info)
    {
    	double latitude = 0.0000;
            double longitude = 0.0000;
    	
     	latitude = info.coordinate().latitude();
    	longitude = info.coordinate().longitude();
    	QVariant lat(latitude);
    	QVariant longi(longitude);
    	
    	if(latitude == 0.0000)
    	{
    	  
    		ui->lineEdit_Latitude_2->setText(lat.toString());
    	}
    	else
    	{
    		ui->lineEdit_Latitude_2->setText(lat.toString());
    	}
    	if(longitude == 0.0000)
    	{
    		ui->lineEdit_Longitude_2->setText(longi.toString());
    	}
    	else
    	{
    	   
    		ui->lineEdit_Longitude_2->setText(longi.toString());
    	}
    		
    
    
    	checkandHitUrl(double value);
    		
    	
    	
    }

    Below is Code for checkandHitUrl(double valuee) :

    Code:
    void LatLong::checkandHitUrl(double value)
    	{
    	    
    	if(some condition)
    			  {		            
    			      flag = true;		  
    			  }
    		  
    		  else if(some condition)
    			  {
    			    set = true;
    			    flag = false;
    			  }
    	
    		  else
    			   {
    		            flag = false;
    		       }
    		  
    		if(flag)
    			{
    			   set = false;
    	                   QUrl url("My URL");   
    			   QNetworkReply* reply = nam->get(QNetworkRequest(url));
    			}
    		
    		else
    			{
    		        //Do nothing
    	     	}
      
    	}

    Below is Code for finishedslot which is Never Called :



    Code:
    void LatLong::finishedslot(QNetworkReply* reply)
    	{  
    	  
    		if (reply->error() == QNetworkReply::NoError)
    	        {
    	           
    	              QByteArray bytearray = reply->readAll();
    	              QString byte_to_string(bytearray); // string
    		      QString trimstr= byte_to_string.trimmed();
    				  
    		      QMessageBox::information(this,"Info",trimstr);
    				  
    				  if(condition)
    					  {
    					  QMessageBox::information(this,"Info","info");
    					  }
    				  else
    					  {
    					  QMessageBox::information(this,"Info",trimstr);
    					  }
    				  
    				  
    	        }
    		
    		else
    		        {
    		             QMessageBox::information(this,"Error","Error Hitting URL.");
    		        }
    		   
    		    reply->deleteLater();
    	
    	    
    	   
    	}



    Can any one help me on this issue:

    Regards,

    Vishal

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

    Re: NetworkReply (finished Slot) with Position update Slot

    hi,

    I found solution I made a silly Mistake I was Using Wrong Signal

    Before (Wrong One):

    Code:
    connect(namanager,SIGNAL(finishedslot(QNetworkReply*)),this,SLOT(finishedslot(QNetworkReply*)));
    After WriteOne:

    connect(namanager,SIGNAL(finished(QNetworkReply*)),this,SLOT(finishedslot(QNetworkReply*)));


    Regards,
    Vishal

  3. #3
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: NetworkReply (finished Slot) with Position update Slot

    Qt always prints a debug message to the debugger on Windows or to the stderr on Linux, when you try to connect something, which do not exist. Checking this output saves dozens of working hours.

    And why do you have code like this?
    Code:
            double latitude = 0.0000;
    	
     	latitude = info.coordinate().latitude();
    	QVariant lat(latitude);
    	
    	if(latitude == 0.0000)
    	{
    	  
    		ui->lineEdit_Latitude_2->setText(lat.toString());
    	}
    	else
    	{
    		ui->lineEdit_Latitude_2->setText(lat.toString());
    	}
    You can reduce it to
    Code:
    	ui->lineEdit_Latitude_2->setText(QString("%1").arg(info.coordinate().latitude()));

  4. #4
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: NetworkReply (finished Slot) with Position update Slot

    I always use an assertion to check connect() return codes:
    Code:
    bool ok;
    ok = connect(...);
    Q_ASSERT(ok);
    Q_UNUSED(ok);
    It saves me a lot of debugging time.

    Quote Originally Posted by vishalrocks101 View Post
    hi,

    I found solution I made a silly Mistake I was Using Wrong Signal

    Before (Wrong One):

    Code:
    connect(namanager,SIGNAL(finishedslot(QNetworkReply*)),this,SLOT(finishedslot(QNetworkReply*)));
    After WriteOne:

    connect(namanager,SIGNAL(finished(QNetworkReply*)),this,SLOT(finishedslot(QNetworkReply*)));


    Regards,
    Vishal

Posting Permissions

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