예제 #1
0
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);
}
예제 #2
0
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);
}