libmaia: XML-RPC with Qt4

So, now that my exams are all done I finally found some time to put up a library you might find useful.
Two semesters ago Karl Glatz and I both needed a XML-RPC library for Trolltechs Qt 4.

Qt4

We first looked around what was already there:

  • QuteXR: a very good lib implementing the server and client side. Sadly only Qt 3. Has many features and so wasn’t easy to port over to Qt4 in the short time we had for our Projects.
  • KRPC: only implements the client side. But we could use some code here.
  • QxtXmlRpc: I found out about this one only recently. And also only implements the client.

So we had to create something new. Luckily we were able to use some code from KRPC and had some inspiration from QuteXR.

To demonstrate how easy it is to use libmaia: two examples.

Let’s create a Server first using these simple lines of code:

QLineEdit *sometext = new QLineEdit(this);
MaiaXmlRpcServer *server = new MaiaXmlRpcServer(8080, this);
server->addMethod("examples.displaytext", sometext, "setText");

First we create a QLineEdit for demonstration purpose.
Then we start the XmlRpc Server on port 8080.
In line 3 we register the Method “examples.displaytext” to the QLineEdits slot “setText”.
You can now remotely call “examples.displaytext” with a String as parameter and change the content of your LineEdit.

Now create a client:

MaiaXmlRpcClient *rpc = new MaiaXmlRpcClient(QUrl("http://localhost:8080/RPC2"), this);
rpc->call("examples.displaytext", QDateTime::currentDateTime().toString("hh:mm:ss"),
this, SLOT(testResponse(QVariant &)),
this, SLOT(testFault(int, const QString &)));

Here we create the client object by passing the server URL to the constructor.
Calling a Method is as easy as passing its name, the arguments and two slots to the “call” method.
The first of the two slots is used to handle the response, the second can be used to catch errors.

Looks easy to get started with? Right, so checkout directly from subversion here:

svn co https://svn.frubar.net/svn/libmaia/trunk/

You’ll also find further examples there.

Have fun with it :)

8 Responses to “libmaia: XML-RPC with Qt4”

  1. dz Says:

    The lib is really nice, thx a lot.

    but in the spec of xmlrpc the date is not so formated, like qt does!

    in libMaia - maiaObject.cpp

    } case QVariant::DateTime: {

    // QString textValue = arg.toDateTime().toString(Qt::ISODate);
    QString textValue = arg.toDateTime().toString(”yyyyMMddThh:mm:ss”);

    Best regards
    dz

  2. wiedi Says:

    Oh, thanks, i’ll fix it :)

  3. dz Says:

    Wie ist es am sinnvollsten mehrere call nacheinander zu machen. zB login -> abfrage -> logout. ohne über die response Funktion das nächste zu triggern. zu ne Art Queue?

    dz

  4. wiedi Says:

    Hmmm Login->Abfrage->Logout ist glaube ich vom Prinzip her ungeschickt. Besser wäre dafür HTTP Auth zu verwenden (das kann libmaia noch nicht).

    Verkettete Calls könnte man aber an sich schon von einer Klasse managen lassen, welche die in einer Queue abarbeitet. Von der Response sollte das ja dann aber trotzdem getriggert werden, sonst braucht man ja keine Queue.

    Die Queue Klasse kann auch alle Responses auf einen Slot connecten um dann weiter zu schalten, das ist ja kein Problem.

    Falls du so etwas wo implementierst oder Lust hast HTTP Auth für libmaia zu basteln … fände ich interessant :)

  5. toemaz Says:

    Thanks for sharing the lib!
    Do you plan to publish it somewhere in e.g. code.google.com or any other project tracker?

  6. dz Says:

    Nochmal Kompliment, nette lib.

    Wenn du libmaia unter lgpl bei sourceforge hostest, wurde ich mich “HTTP Auth” und https annehmen.

  7. silver Says:

    Thanks for your work! Great lib! But it has small memory leak. To fix it, edit maiaXmlRpcServerConnection.cpp file to be like


    MaiaXmlRpcServerConnection::~MaiaXmlRpcServerConnection() {
    clientConnection->deleteLater();
    delete header; //

  8. wiedi Says:

    thanks, fix committed

Leave a Reply