How to Make Your Window Stay on Top in Qt

You can use the following snippet to make your MainWindow or any other window always on top:

setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);

Just insert it in your window’s constructor function.



How to Access Android Camera Using Qt/C++

In this article I am going to describe the required steps needed for accessing Android Camera (or Default Camera Interface) using Qt. Unfortunately OpenCV does not provide a reliable way of connecting to Camera in Android so you have go for a method like this if you intend to write an Android application which uses OpenCV and Qt together. I strongly recommend that you should first read this article (which describes how to access Android Gallery from Qt) and also this article (which shows how to mix Java and C++ code in Qt) and then return here because I will be assuming that you are familiar with those processes. So if you can already access Android Gallery using Qt then continue reading the steps described below.

Continue reading “How to Access Android Camera Using Qt/C++”

How to Convert QBuffer to QString

You can convert QBuffer to QString using buffer function of the QBuffer. Here is how you can do it.

QBuffer b;
b.open(QBuffer::ReadWrite);
b.write("http://amin-ahmadi.com");
QString str = b.buffer();
qDebug() << str; // "http://amin-ahmadi.com"
b.close();


Fix ModSecurity Issues in Qt Network Module Download Functionality

You might have come across the following (Not Acceptable) error when trying to download files from some websites using Qt. This error message is generated by ModSecurity and it usually means that for some reason the web server does not allow downloading of the file using the method you are trying. In my case it was because of the User-Agent Header set to a value not allowed by the server. So here is how I fixed it:

Continue reading “Fix ModSecurity Issues in Qt Network Module Download Functionality”

How to Create an Empty QImage to Play Around With

You can create a QPixmap and convert it to QImage if you just want to have a QImage for modification and manipulation. Here, you can use the following code to achieve this:

int width = 100;
int height = 200;
QImage image = QPixmap(width, height).toImage();