Skip to content

Instantly share code, notes, and snippets.

@barneywilliams
Created September 20, 2012 14:40
Show Gist options
  • Save barneywilliams/3756323 to your computer and use it in GitHub Desktop.
Save barneywilliams/3756323 to your computer and use it in GitHub Desktop.
JSONSocket - Qt JSON parsing and validation
QString Client::ProcessCommand(QScriptValue req)
{
QScriptValue cmd = req.property("command");
QString response;
// Basic sanity check
if (!cmd.isValid())
{
response = CommandErrorResponse("invalid", "No command specified");
}
// Process greeting
else if (cmd.toString() == "greeting")
{
QScriptValue message = req.property("message");
if (!message.isValid())
{
response = CommandErrorResponse("greeting", "No message specified");
}
else
{
response = CommandResponse("greeting", "Hello server. Hope things are well!");
}
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment