C++ API for "Text To speech" and "Voice to Text" - c++

I would like to know whether there is a good API for "voice recognition" and "text to speech" in C++. I have gone through Festival, which you can't even say whether the computer is talking because it is so real and voce as well.
Unfortunately Festival seems not supporting to voice recognition (I mean "Voice to Text") and voce is built in Java and it is a mess in C++ because of JNI.
The API should support both "Text to voice" and "Voice to Text", and it should have a good set of examples, at least outside the owner's website. Perfect if it has a facility to identify set of given voices, but that is optional, so no worries.
What I am going to do with the API is, when set of voice commands given, turn the robot device left, right, etc. And also, speak to me saying "Good Morning", "Good Night" etc. These words will be coded in the program.
Please help me to find a good C++ voice API for this purpose. If you have access to a tutorial/installation tutorial, please be kind enough to share it with me as well.

I found that If I make a audio recording (I used qtmultimedia for this) has to be flac
Read more here
I can then upload to google and then have it send me back some JSON
I then wrote some c++/qt for this to make into a qml plugin
Here is that (alpha) code. Note make sure that you replace
< YOUR FLAC FILE.flac >
with your real flac file.
speechrecognition.cpp
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QSslSocket>
#include <QUrl>
#include <QJsonDocument>
#include <QJsonArray>
#include <QJsonObject>
#include "speechrecognition.h"
#include <QFile>
#include <QDebug>
const char* SpeechRecognition::kContentType = "audio/x-flac; rate=8000";
const char* SpeechRecognition::kUrl = "http://www.google.com/speech-api/v1/recognize?xjerr=1&client=directions&lang=en";
SpeechRecognition::SpeechRecognition(QObject* parent)
: QObject(parent)
{
network_ = new QNetworkAccessManager(this);
connect(network_, SIGNAL(finished(QNetworkReply*)),
this, SLOT(replyFinished(QNetworkReply*)));
}
void SpeechRecognition::start(){
const QUrl url(kUrl);
QNetworkRequest req(url);
req.setHeader(QNetworkRequest::ContentTypeHeader, kContentType);
req.setAttribute(QNetworkRequest::DoNotBufferUploadDataAttribute, false);
req.setAttribute(QNetworkRequest::CacheLoadControlAttribute,
QNetworkRequest::AlwaysNetwork);
QFile *compressedFile = new QFile("<YOUR FLAC FILE.flac>");
compressedFile->open(QIODevice::ReadOnly);
reply_ = network_->post(req, compressedFile);
}
void SpeechRecognition::replyFinished(QNetworkReply* reply) {
Result result = Result_ErrorNetwork;
Hypotheses hypotheses;
if (reply->error() != QNetworkReply::NoError) {
qDebug() << "ERROR \n" << reply->errorString();
} else {
qDebug() << "Running ParserResponse for \n" << reply << result;
ParseResponse(reply, &result, &hypotheses);
}
emit Finished(result, hypotheses);
reply_->deleteLater();
reply_ = NULL;
}
void SpeechRecognition::ParseResponse(QIODevice* reply, Result* result,
Hypotheses* hypotheses)
{
QString getReplay ;
getReplay = reply->readAll();
qDebug() << "The Replay " << getReplay;
QJsonDocument jsonDoc = QJsonDocument::fromJson(getReplay.toUtf8());
QVariantMap data = jsonDoc.toVariant().toMap();
const int status = data.value("status", Result_ErrorNetwork).toInt();
*result = static_cast<Result>(status);
if (status != Result_Success)
return;
QVariantList list = data.value("hypotheses", QVariantList()).toList();
foreach (const QVariant& variant, list) {
QVariantMap map = variant.toMap();
if (!map.contains("utterance") || !map.contains("confidence"))
continue;
Hypothesis hypothesis;
hypothesis.utterance = map.value("utterance", QString()).toString();
hypothesis.confidence = map.value("confidence", 0.0).toReal();
*hypotheses << hypothesis;
qDebug() << "confidence = " << hypothesis.confidence << "\n Your Results = "<< hypothesis.utterance;
setResults(hypothesis.utterance);
}
}
void SpeechRecognition::setResults(const QString &results)
{
if(m_results == results)
return;
m_results = results;
emit resultsChanged();
}
QString SpeechRecognition::results()const
{
return m_results;
}
speechrecognition.h
#ifndef SPEECHRECOGNITION_H
#define SPEECHRECOGNITION_H
#include <QObject>
#include <QList>
class QIODevice;
class QNetworkAccessManager;
class QNetworkReply;
class SpeechRecognition : public QObject {
Q_OBJECT
Q_PROPERTY(QString results READ results NOTIFY resultsChanged)
public:
SpeechRecognition( QObject* parent = 0);
static const char* kUrl;
static const char* kContentType;
struct Hypothesis {
QString utterance;
qreal confidence;
};
typedef QList<Hypothesis> Hypotheses;
// This enumeration follows the values described here:
// http://www.w3.org/2005/Incubator/htmlspeech/2010/10/google-api-draft.html#speech-input-error
enum Result {
Result_Success = 0,
Result_ErrorAborted,
Result_ErrorAudio,
Result_ErrorNetwork,
Result_NoSpeech,
Result_NoMatch,
Result_BadGrammar
};
Q_INVOKABLE void start();
void Cancel();
QString results()const;
void setResults(const QString &results);
signals:
void Finished(Result result, const Hypotheses& hypotheses);
void resultsChanged();
private slots:
void replyFinished(QNetworkReply* reply);
private:
void ParseResponse(QIODevice* reply, Result* result, Hypotheses* hypotheses);
private:
QNetworkAccessManager* network_;
QNetworkReply* reply_;
QByteArray buffered_raw_data_;
int num_samples_recorded_;
QString m_results;
};
#endif // SPEECHRECOGNITION_H

if you develop on Windows you can use MS Speech API which allow you to perform Voice Recognition (ASR) and Text-to-Speech (TTS).
You can find some examples on this page and a very basic example of Voice Recognition in this post.

You could theoretically use Twilio if you have an internet connection in the robot and are willing to pay for the service. They have libraries and examples for a bunch of different languages and platforms http://www.twilio.com/docs/libraries
Also, check out this blog explaining how to build and control an arduino based robot using Twilio http://www.twilio.com/blog/2012/06/build-a-phone-controlled-robot-using-node-js-arduino-rn-xv-wifly-arduinoand-twilio.html

Related

Multiple get/post calls using a wrapper class with Qt

I am working on a Qt project with a team. I have two functions — one retrives the numerical coordinates of a place, the other downloads the map of the place — that I want to merge in one wrapper class, so that my teammates can call it easily.
#include <QCoreApplication>
#include <QFile>
#include <QHttpMultiPart>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <iostream>
class OpenStreetMapWrapper: public QObject{
Q_OBJECT
public:
OpenStreetMapWrapper(QObject *parent=nullptr):QObject(parent){
connect(&manager, &QNetworkAccessManager::finished, this, &OpenStreetMapWrapper::handle_finished);
}
void download(const std::string &region, const std::string &department, const QFile& outfile){
QNetworkRequest request;
QUrl url = QUrl(QString::fromStdString("https://download.openstreetmap.fr/extracts/europe/france/" + region + "/" + department + ".osm.pbf"));
request.setUrl(url);
request.setAttribute(QNetworkRequest::User, outfile.fileName());
manager.get(request);
}
void searchCSV(QFile& file, QFile& outfile){
QNetworkRequest request(QUrl("https://api-adresse.data.gouv.fr/search/csv/")); // Free API provided by the French government
request.setAttribute(QNetworkRequest::User, outfile.fileName());
QHttpMultiPart *multipart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
QHttpPart postpart;
postpart.setHeader(QNetworkRequest::ContentDispositionHeader,
QString("form-data; name=%1; filename=%2")
.arg("data", file.fileName()));
postpart.setBodyDevice(&file);
multipart->append(postpart);
file.setParent(multipart);
manager.post(request, multipart);
}
private:
QNetworkAccessManager manager;
void handle_finished(QNetworkReply *reply){
if(reply->error() == QNetworkReply::NoError){
QByteArray read = reply->readAll();
std::cout << read.toStdString() << std::endl; // For debugging
QString filename = reply->request().attribute(QNetworkRequest::User).toString();
QFile out(filename);
if(out.open(QIODevice::WriteOnly)){
out.write(read);
out.close();
}
}
else{
qDebug() << reply->error() << reply->errorString();
}
reply->deleteLater();
// QCoreApplication::quit(); This is done somewhere else?
}
};
#include <main.moc>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
OpenStreetMapWrapper A;
QFile file("./search.csv");
file.open(QIODevice::ReadWrite);
QFile outfile("./output.csv");
outfile.open(QIODevice::ReadWrite);
// Search
A.searchCSV(file, outfile); // 1st call works
A.searchCSV(file, outfile); // 2nd call -> makes both calls fail.
// Downloader
std::string region = "corse";
std::string department = "haute_corse";
return a.exec();
}
The problem with the code above, is that when for example searchCSV is called it displays the output as needed, but if it is called twice in the code, there is no output at all. After some debugging I think the problem is that the manager and handle_finished are not connected properly, because the execution never reaches there. Is there a simple way to solve this issue? Ideally, there is just one class instant, and any method can be called any number of times.
I don't know much about Qt, but it looks like you're trying to read from file twice and my guess is that when it reaches the end of the file after the first call to A.searchCSV it is done and you can't read from it anymore - unless you reposition the QFile to the beginning of the file.
Possible solution:
A.searchCSV(file, outfile);
file.unsetError(); // possibly needed
file.seek(0); // rewind to the start of the file
A.searchCSV(file, outfile);
The two QFile (input, output) are shared between two asynchronous calls (searchCSV) that might give an undefined behavior. The input file (stream) contents will be load and push only after the connection was made (like curl does).
You should:
Make searchCSV a blocking function (wait until handle_finished() done), input file pointer should be reinitialized before an other call.
OR: Use separated input/output QFile instances

Memory access error when using QNetworkManager

I'm fairly new to C++ (though I have some experience with C) as well as QT. I'm trying to make a program that POSTs to a website when the user clicks a button, but whenever I try to access QNetworkManager I get a memory access error.
The code for my request object is as follows (trimmed slightly to show the important bits):
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QUrl>
#include "cJSON.h"
class unifiedRequests: public QObject {
Q_OBJECT
public:
// Members
QString access_token = "";
bool admin = false;
// Methods
explicit unifiedRequests(QObject *parent=0);
QNetworkReply* login_request(QString *email, QString *password);
signals:
public slots:
void login_complete(QNetworkReply *reply);
void sslErrorHandler(QNetworkReply*, const QList<QSslError> & );
private:
QNetworkRequest make_headers(QByteArray endpoint);
QNetworkRequest make_headers(QByteArray endpoint, QByteArray *access_token);
};
QNetworkRequest unifiedRequests::make_headers(QByteArray endpoint) {
QString url = endpoint.prepend("https://dali.vpt.co.uk");
QNetworkRequest request = QNetworkRequest(url);
qDebug() << "Setting Headers";
request.setRawHeader("User-Agent", "Desktop Client Debug");
request.setRawHeader("Content-Type", "application/json");
qDebug() << "Set headers successfully.";
return request;
}
void unifiedRequests::sslErrorHandler
(QNetworkReply* reply, const QList<QSslError> & errors) {
qDebug() << "Ignoring SSL Errors";
};
QNetworkReply* unifiedRequests::login_request
(QString *email, QString *password) {
QNetworkRequest request = make_headers("/api/auth");
qDebug() << "Making JSON";
cJSON *login_json; //The body of the request
login_json = cJSON_CreateObject();
cJSON_AddStringToObject(login_json, "email", email->toUtf8());
cJSON_AddStringToObject(login_json, "password", password->toUtf8());
qDebug() << "Made JSON: ";
qDebug() << cJSON_Print(login_json);
QNetworkAccessManager *manager = new QNetworkAccessManager;
//The object we use to send the request and receive the reply
qDebug() << "Turning off SSL";
connect(manager,
SIGNAL(sslErrors(QNetworkReply*, const QList<QSslError> & )),
this,
SLOT(sslErrorHandler(QNetworkReply*, const QList<QSslError> & )));
qDebug() << "POSTing login.";
QNetworkReply *reply = manager->post(request, cJSON_Print(login_json));
qDebug() << "Connecting signal to slot.";
QAbstractSocket::connect(manager, SIGNAL(finished(QNetworkReply * )),
this, SLOT(login_complete(QNetworkReply * )));
cJSON_Delete(login_json);
return reply;
}
I'm creating the unifiedRequests object by calling:
unifiedRequests requestObj;
in a different file. It crashes out on the line where I try to turn off SSL (we're using a self-signed certificate, so I need to do this in order to make the request). Any thoughts?
Thank you!
You create the unifiedRequests object by calling "unifiedRequests requestObj;", this object will be deleted when the variable "requestObj" goes out of scope.
So, when the signal will be received, the object will be already destroyed.
Try to create your unifiedRequests object by calling "unifiedRequests* requestObj = new unifiedRequests();".
Of course, you need to call "delete requestObj;" somewhere to destroy this object. Where and when depend on your application (when you don't need this object anymore).
To understand the difference, look at here : http://www.tutorialspoint.com/cplusplus/cpp_dynamic_memory.htm
Or google for "C++ heap / stack / dynamic allocation"

Client Server program in qt

I am new in Qt, I want to write a simple client server program that client send a message to server and server get it and send it back to client.I wrote the server program but i have problem in client and I don't know how should I write it. could you please help me?
Here is my client code:
#include "myclient.h"
#include "QTcpsocket"
#include "QTcpServer"
#include "mainwindow.h"
Client::Client(QObject* parent): QObject(parent)
{
connect(&client, SIGNAL(connected()),this, SLOT(sendData()),Qt::DirectConnection);
}
void myclient::attemptConnection()
{
connect(QTcpSocket, SIGNAL(newConnection()), this, SLOT(connectionAccepted()));
if(QTcpSocket->listen("127.0.0.1",1234))
{
qDebug() << "Server listening";
}
else
{
qDebug() << "Couldn't listen to port" << server->serverPort() << ":" << server->errorString();
}
}
void myclient::connect()
{
QTcpSocket->connectToHost(LocalHost,1234,QIODevice::ReadWrite);
if(QTcpSocket->waitForConnected())
{
QString string = "Hello";
QByteArray array;
array.append(string);
qDebug()<<QTcpSocket->write(array);
}
else
{
qDebug() << "couldn't connect";
}
}
QTcpSocket socket;
void myclient::connectionAccepted()
{
qDebug()<<"Connected";
connect(socket, SIGNAL(readyRead()), this, SLOT(readSocket()));
}
void myclient::readSocket()
{
qDebug()<<socket->readBufferSize();
QByteArray = socket->readAll();
}
I think You Should take A look at the Forutne Client Example From Qt Docs, And base your code on it.
In your code you are using Both Blocking Functions from the waitFor*(), And Non-Blocking signals/slots (readyRead() signal), The Non-Blocking approach is Highly recommended (especially if the code is executed in the GUI thread).
Also I am not sure about your function attemptConnection, which uses newConnection() signal, new Connection is not even a member of QTcpSocket.

Looping through QNetworkAccessManager get() routines, retrieve order on finish

I have a QNetworkAccessManager as a member of my class. I connect the finished signal from this manager to the replyFinished function I have written.
manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)),this,SLOT(replyFinished(QNetworkReply*)));
In a separate routine, I loop through a get call from the manager
for (int si = 0; si<numLines; si++)
{
QString line = lines[si];
manager->get(QNetworkRequest(QUrl(line)));
}
In my replyFinished slot routine, I know I may not receive the signals in the order they were performed in the loop, but is there any way I can obtain that information? That is, is there a clever way I can obtain "si" in my replyFinished routine? Thanks for the help!
QNetworkAccessManager::get() returns a pointer to the QNetworkReply object. This pointer is the same one that is passed your replyFinished() slot. You can use a QMap to store pairings of QNetworkReply* pointers and integers (si in your code).
Here is a working example;
#include <QCoreApplication>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QUrl>
#include <QMap>
#include <QtDebug>
QNetworkAccessManager am;
void finished(QNetworkReply* reply);
QMap<QNetworkReply*, int> requests;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QObject::connect(&am, &QNetworkAccessManager::finished, finished);
QStringList links;
links << "http://google.com";
links << "http://taobao.com";
links << "http://stackoverflow.com";
links << "http://stackexchange.com";
links << "http://bing.com";
for (int i=0; i < links.size(); i++)
{
requests.insert(am.get(QNetworkRequest(QUrl(links[i]))), i);
}
return a.exec();
}
void finished(QNetworkReply* reply)
{
qDebug() << requests[reply];
}
The slot replyFinished(QNetworkReply*) receives pointer to the related reply object. This reply object contains all information about that reply (error code, headers, downloaded data, the URL of the content) and also it contains initial request (QNetworkReply::request()). So, it is possible to check the URL of the request or the URL of actual downloaded content. Note that those URLs may be different.
QNetworkReply::url():
Returns the URL of the content downloaded or uploaded. Note that the
URL may be different from that of the original request.
QNetworkReply::request():
Returns the request that was posted for this reply. In special, note
that the URL for the request may be different than that of the reply.
void MainWindow::replyFinished(QNetworkReply* reply)
{
qDebug() << reply->url();
qDebug() << reply->request().url();
}

Signal-Slot makes a mess

I am trying to create a image-saving application using Qt. Now the stub
class ImageSaver:public QObject
{
int index;
QWebPage * main_Page;
QNetworkAccessManager * manager;
QNetworkReply * reply;
QString file_Name;
QSet<QString> image_Addresses;
QString web_Address;
Q_OBJECT
signals:
void image_Saved();
public slots:
void request_Image();
void on_Finished(bool status);
void got_Reply(QNetworkReply * reply);
public:
ImageSaver();
void start();
};
ImageSaver::ImageSaver()
{
index = 0;
manager = new QNetworkAccessManager;
reply = NULL;
connect(main_Page,SIGNAL(loadFinished(bool)),this,SLOT(on_Finished(bool)));
connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(got_Reply(QNetworkReply*)));
connect(this,SIGNAL(image_Saved()),this,SLOT(request_Image()));
}
void ImageSaver::start()
{
//loads the url
// In the end of the loading it will emit load_Finished(bool)
// So that signal will execute on_Finished(bool)
}
void ImageSaver::request_Image()
{
QString temp_Address = *(image_Addresses.begin()+index);
//makes a request to the server to give the image "temp_Address"
//When the server gives the reply signal finished(QNetworkReply*) will be emitted
// this in turn will call the got_Reply(QNetworkReply*)
}
void ImageSaver::on_Finished(bool status)
{
//collects all the images's url addresses, and pushes them in the list
//"image_Addresses"
//Then emits image_Saved();
//This signal will wake up the function request_Image()
}
void ImageSaver::got_Reply(QNetworkReply * reply)
{
//Image is extracted from the reply and got saved in the same name as in the page
//index got increased;
//emits the signal image_Saved();
//This signal will activate the function request_Image()
}
int main(int argc,char * argv[])
{
QApplication app(argc,argv);
ImageSaver a;
a.start();
return app.exec();
}
#include "main.moc"
In short First call is to "start".That calls "on_Finished" and there is no problem untill this. So all the image files's addresses got pushed in the list. Next is one by one request for image[i] made, and the reply image got saved. This thing is happening repeatedly. Here only I am getting problem. Crashes are appearing in this operation especially in saving the image.
My assumption is "signal-slot" is not like function call, thy are more or less like thread but operates on the same function( pointer). So when one signal requests for painter, which is already rendering something then the crash will appear.
Can anybody say the fact behind the crash and how to save all the images without crash?
EDIT:
Hi, This is the full code. Run this one, and click the message boxes contineously
#include <QApplication>
#include <QDir>
#include <QImage>
#include <QObject>
#include <QMessageBox>
#include <QPainter>
#include <QPixmap>
#include <QSet>
#include <QTimer>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
#include <QtNetwork/QNetworkRequest>
#include <QtWebKit/QWebElement>
#include <QtWebKit/QWebFrame>
#include <QtWebKit/QWebPage>
#include <QUrl>
class ImageSaver:public QObject
{
int index;
QWebPage * main_Page;
QNetworkAccessManager * manager;
QNetworkReply * reply;
QString file_Name;
QSet<QString> image_Addresses;
QString web_Address;
Q_OBJECT
signals:
void image_Saved();
public slots:
void request_Image();
void on_Finished(bool status);
void got_Reply(QNetworkReply * reply);
public:
ImageSaver();
void start();
protected:
//void show_Frame(QWebFrame * frame);
};
ImageSaver::ImageSaver()
{
index = 0;
this->main_Page = new QWebPage;
manager = new QNetworkAccessManager;
reply = NULL;
connect(main_Page,SIGNAL(loadFinished(bool)),this,SLOT(on_Finished(bool)));
connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(got_Reply(QNetworkReply*)));
connect(this,SIGNAL(image_Saved()),this,SLOT(request_Image()));
}
void ImageSaver::start()
{
web_Address = "yahoo.com";
QDir dir;
dir.mkdir(web_Address);
QUrl url = QUrl::fromUserInput(web_Address);
main_Page->mainFrame()->load(url);
}
void ImageSaver::request_Image()
{
QString temp_Address = *(image_Addresses.begin()+index);
int a = temp_Address.lastIndexOf("/");
file_Name = temp_Address.mid(a+1);
//Without the below message box, the program closes shortly
//This message box is slowing down that effect
QMessageBox hh;
hh.setText(file_Name);
hh.exec();
QNetworkRequest request= QNetworkRequest(QUrl(temp_Address));
request.setRawHeader("img","src");
manager->get(request);
}
void ImageSaver::on_Finished(bool status)
{
if(status)
{
QMessageBox mm;
mm.setText("Finished");
mm.exec();
QWebElementCollection temp_Collection= main_Page->mainFrame()->findAllElements("*");
for(int i=0;i<temp_Collection.count();++i)
{
QWebElement temp_Element = temp_Collection[i];
if(temp_Element.tagName().contains("img",Qt::CaseInsensitive) && temp_Element.attributeNames().contains("src",Qt::CaseInsensitive))
{
QString image_Web_Address = temp_Element.attribute("src");
if(!image_Addresses.contains(image_Web_Address))
image_Addresses.insert(image_Web_Address);
}
}
emit image_Saved();
QMessageBox kk;
kk.setText("Image is going to be saved");
kk.exec();
}
else
{
QMessageBox mm;
mm.setText("Not ready");
mm.exec();
}
QMessageBox mm;
mm.setText("Getting out of finished");
mm.exec();
}
void ImageSaver::got_Reply(QNetworkReply * reply)
{
QImage image;
if(image.load(static_cast<QIODevice *>(reply),0))
image.save(web_Address+QDir::separator()+file_Name,0);
++index;
emit image_Saved();
}
/*
void ImageSaver::show_Frame(QWebFrame * temp_Frame)
{
QImage image(temp_Frame->contentsSize(),QImage::Format_ARGB32_Premultiplied);
image.fill(Qt::transparent);
QPainter painter(&image);
painter.setRenderHint(QPainter::Antialiasing,true);
painter.setRenderHint(QPainter::TextAntialiasing,true);
painter.setRenderHint(QPainter::SmoothPixmapTransform,true);
temp_Frame->documentElement().render(&painter);
painter.end();
foreach(QWebFrame * temp_Frame0,temp_Frame->childFrames())
show_Frame(temp_Frame0);
}
*/
int main(int argc,char * argv[])
{
QApplication app(argc,argv);
ImageSaver a;
a.start();
return app.exec();
}
#include "main.moc"
This is the pro file
QT += webkit network
SOURCES += \
main.cpp
Your code crashes because you read beyond the boundaries of the image_Addresses set.
void ImageSaver::request_Image()
{
QString temp_Address = *(image_Addresses.begin()+index);
...
You increment index after every image received, but there isn't any check anywhere in the code whether index is still less than image_Addresses.size(), so it crashes once dereferencing image_Addresses.begin()+index for index == image_Addresses.size().
There may be many solutions to this problem. I think that you should have a look at The State Machine Framework. In easy situations you can just use boolean variable to check if you can go on. You should also think what to do when you're busy processing the image. You can queue request or just reject them. Also you can implement threading, so that new requests are served by new threads.
P.S. Signals are more like events than threads to me.
What's the error and why do you have a #include at the end?
FYI there is a QImage class you can use instead which includes saving and loading from a QIODevice* such as QNetworkReply for example. It's extremely rare to need to reinvent the wheel in the massive framework that is Qt.