In this article I am going to describe how to get the title of the window which has the focus, or in other word is currently active. To be able to achieve this in Qt/C++ you need to use the operating system API functions, in this case Win32 API.
Continue reading “How to Get the Topmost Window Title using Qt/C++ (for Windows)”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++”Quick Way to Find the Sum or Average of All Elements in QByteArray
There are scenarios where you would need to find the sum or the average of all values in a QByteArray. This can specially happen if you are trying to send data using COM ports to devices that require the average or sum (or a similar combination) of all elements in order to check the integrity of data.
Continue reading “Quick Way to Find the Sum or Average of All Elements in QByteArray”How to Convert Data to/from Base64 in Qt
Qt Framework implements many convenience functions inside QByteArray for quickly handling of raw data. One of the widely used encoding methods is Base64 and if you’re with Qt, you can easily convert any string (QString) to/from Base64.
Continue reading “How to Convert Data to/from Base64 in Qt”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();
How to Create and Use Buffers in Qt
Qt Framework includes a class called QBuffer that can be used to access a QByteArray (internal QByteArray to be precise) as if it is a file. So you can use Stream readers and writers to access data in it similar to a QFile.
Continue reading “How to Create and Use Buffers in Qt”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();
How to handle Canon EOS RAW images in C++/Qt
RAW, or to put it in terms of file extension, CR2 and CRW files are the images produced using Canon EOS cameras. A RAW photo, as it appears from it’s name, is the raw format of the image, meaning it contains the exact binary data that was recorded by a specific camera when the photo was taken.
Continue reading “How to handle Canon EOS RAW images in C++/Qt”