void TestCaller::callMegaString() { QMutexLocker locker(&mutex); qDebug() << "Iteration!" << this << thread() << QThread::currentThread(); ReturnValue ret = largeValues(megaString); QString value = ret.isError() ? ret.errString() : ret.toString(); if (value != megaString) qFatal(qPrintable(QString("ERROR: Malformed megastring: %1 (%2)").arg(value).arg(ret.errString()))); }
int main(int argc, char *argv[]) { QCoreApplication app(argc,argv); //Create an instance of the service object BasicService service; //Connect to the server using an incorrect password ReturnValue ret = service.connect("tcp://*****:*****@localhost:10123/MyService"); //If the connection failes, ret.isError() will be true if(ret.isError()) { qDebug() << "Failed to connect:" << ret; qDebug() << "This was expected."; } //Connect to the server using the correct username and password ret = service.connect("tcp://*****:*****@localhost:10123/MyService"); //If the connection failes, ret.isError() will be true if(ret.isError()) { //You can use ReturnValues in qDebug() statements to quickly print error messages. qCritical() << "Failed to connect:" << ret; return(1); } //Run the remove function. This will block untill the function returns, //Or untill the default time-out is reached ret = service.addNumbers(3,5); if(ret.isError()) { qCritical() << "Failed to call addNumbers():" << ret; return(1); } //You can use ReturnValue just like a QVariant qDebug() << "Call to add() succeeded."; qDebug() << "Result:" << ret.toInt(); qDebug(); //Calling this function will return an error. ret = service.returnError(); if(ret.isError()) { //The ReturnValue class can be used to inspect the error. qDebug() << "Failed to call returnError():" << ret; qDebug() << "Error Number:" << ret.errNumber(); qDebug() << "Error String:" << ret.errString(); qDebug() << "This was expected"; } return(0); }
TestCaller::TestCaller(QObject* parent): ClientProxy(parent) { // ServiceFinder* finder = new ServiceFinder("TestService", this); // QObject::connect(finder, SIGNAL(serviceEvent(ServiceFinder::Service)), this, SLOT(serviceEvent(ServiceFinder::Service))); // finder->scan(); ReturnValue ret = connect("tcp://localhost:18777/TestService"); if(ret.isError()) qDebug() << ret.errString(); else qDebug() << ret; ret = somethingElse("this is some text that will become binary data"); if(ret.isError()) qDebug() << ret.errString(); else qDebug() << ret; megaString = "zxcvbnmasdfghjklqwertyuiop"; for (int i = 0 ; i < 2 ; i++) { megaString += megaString; } QObject::connect(this, SIGNAL(testEvent(QString)), this, SLOT(receiveEvent(QString))); }
int main(int argc, char *argv[]) { QCoreApplication app(argc,argv); //Create an instance of the service object DataService service; //Connect to the server, specifying the port, and the remove service to connect to ReturnValue ret = service.connect("tcp://localhost:10123/Data"); //If the connection failes, ret.isError() will be true if(ret.isError()) { //You can use ReturnValues in qDebug() statements to quickly print error messages. qCritical() << "Failed to connect:" << ret; return(1); } //Retrive the custom data. ret = service.getData(); if(ret.isError()) { qCritical() << "Failed to call getData():" << ret; return(1); } //Pull the custom data out of ReturnValue. DataService::CustomData data = ret.value<DataService::CustomData>(); qDebug() << "Custom Data: " << data.x << data.y << data.z; //Retrieve an instance to a service ret = service.getBasicService(); if(ret.isError()) { qCritical() << "Failed to call getBasicService():" << ret; return(1); } //Simply assign an instance of the service class to the returned ReturnValue. BasicService basic = ret; //Then use the service as you normally would. ret = basic.addNumbers(3,5); if(ret.isError()) { qCritical() << "Failed to call addNumbers():" << ret; return(1); } //You can use ReturnValue just like a QVariant qDebug() << "Call to add() succeeded."; qDebug() << "Result:" << ret.toInt(); qDebug(); //Calling this function will return an error. ret = basic.returnError(); if(ret.isError()) { //The ReturnValue class can be used to inspect the error. qDebug() << "Failed to call returnError():" << ret; qDebug() << "Error Number:" << ret.errNumber(); qDebug() << "Error String:" << ret.errString(); qDebug() << "This was expected"; } return(0); }