How To Read EXIF Orientation From JPEG in Qt 4.8.5

For many Qt lovers out there who might want to use third-party EXIF parsing library with their Qt apps, it may prove difficult unless you know what you’re doing. If you’re a hobbyist like me, man, it’s just tough. But there are free EXIF parsers out there, and it might take a little elbow grease to make it work with Qt. In my case, I put together a very simple and basic image viewer that I thought users might appreciate if it auto-rotated any images that contained EXIF metadata such as orientation. In smartphones and DSLRs, there is usually a sensor that records which orientation the picture was taken in. So when you view the photo without orientation applied, it might be a minor nuisance having to manually rotate it. That’s where you come in as software developer and take care of it for the end-user. Continue reading

Posted in Qt | Tagged , , , , , , , , , , | Leave a comment

Fixing Windows 10 Aspect Ratio Scaling Problem For Lower Resolution Display

You may notice if you’re still deploying applications using resolutions less than 800x600x72dpi on Windows 10 that the autoscaling for the aspect ratio might be wonky. That’s because all these new fancy operating systems are trying to cater to ultra high resolution/density screens these days, and if you’re building an old-fashion 2D game engine that doesn’t require too much screen resolution, the final output might be thrown off a bit. Sometimes it’s just the graphics card, but in Windows 10 case, it seems it’s built into the operating system. Anyway, this is how I “fixed” it.

Example of incorrect aspect ratio in Windows 10 auto-scaling fullscreen

Example of incorrect aspect ratio in Windows 10 auto-scaling fullscreen

Continue reading

Posted in Qt, SDXM | Tagged , , , , , , , , , , , | Leave a comment

Qt Real 3D Emulates SNES Mode 7 Prototype Demo

It’s actually a little more advanced than SNES Mode 7 because it’s real 3D. Yes, Nintendo’s Mode 7 was 3D, but the limitation was to the ground plane. I needed to have better understanding of how a 3D engine worked so that mapping of objects went smoothly. So where ever I place a 3D object into the world, is also where I can place a 3D “plane” that I can use a 2D texture as a 3D sprite. For example, say I wanted to put a tree or stop sign on the map for a racing game similar to F-Zero.

Posted in Qt | Leave a comment

Qt 4.8.7 Prerequisites for Windows

Qt 4.8.7 differs greatly from Qt 4.8.5 in that they’ve wanted to provide more access to Windows 7 and later API. This makes the versions’ dependencies incompatible when you distribute your apps. So pay attention.

Downloads (For Distribution/Standalone Runtime):

Required
libgcc_s_dw2-1.dll 48 KB (UPX compressed)
libstdc++-6.dll 409 KB (UPX compressed)
libwinpthread-1.dll 25 KB (UPX compressed)
QtCore4.dll 1.1 MB (UPX compressed)
QtGui4.dll 4.1 MB (UPX compressed)
And for image format support:
/imageformats/ 2.3 MB (UPX compressed)
And for Phonon to work:
phonon4.dll 121 KB (UPX compressed)
QtXml4.dll 143 KB (UPX compressed)
QtDBus4.dll 182 KB (UPX compressed)
/phonon_backend/ 1.5 MB (UPX compressed)
/codecs/ 1.4 MB (UPX compressed)
qt487_dependencies_upx.zip – contains all minimum dependencies to run my Qt 4.8.7 apps NOTE: Not available yet, I’ll update this when I have working demo

Downloads (For Developing):

Qt 4.8.7 SDK qt-opensource-windows-x86-mingw482-4.8.7.exe (337MB)
minGW 64 + GCC 4.8.2 compiler i686-4.8.2-release-posix-dwarf-rt_v3-rev3.7z (46MB)
QtCreator 2.8.0 qt-creator-windows-opensource-2.8.0.exe (52MB) Note: there is newer version 2.8.1 but I don’t need it, so I cannot guarantee ver 2.8.1 will work or is compatible myself

IMPORTANT: If you can’t get Qt 4.8.7 to work for Windows, follow these instructions if you are upgrading from previous version, ie 4.8.5.

Posted in Qt | Leave a comment

Update: Real 3D in Qt 4.8.7 without third-party libraries DirectX or OpenGL

UPDATE!!!!

Is it getting more obvious this is going to work? 😛

Continue reading

Posted in Qt | Leave a comment

Real 3D in Qt 4.8.7 Without Third Party 3D Library OpenGL/DirectX/QTransform

Here’s a demo of “real” 3D in pure Qt. It doesn’t rely on third party 3D libraries like OpenGL, DirectX, or even Qt’s own convenience class QTransform. It’s actually very simple. It uses a very simple trigonometry function for rotating a point you can get off of Wikipedia. Everything else has to be calculated manually, but it works. The geometry is accurate. But so far this is only a work-in-progress and I haven’t quite figured out the texture mapping. But the fact that the faces can have textures mapped to them, yes with QTransform, means it’s ready for Mode 7 if you just want to put up single plane “sprites” as obstacles in an F-Zero or Mario Kart-like game. But I want to have full 3D boxes or buildings or platforms.

So we’ll see. It’s all a learning process for me.

Posted in Qt | Leave a comment

How To Distribute Phonon Apps With Qt 4.8.7

The Phonon documentation provided by Qt isn’t thorough because Qt stopped providing support for it after awhile. So you’ll have to do extensive scouring of the Internet to make even your most basic Phonon app work. Here’s how:

When you’re coding, you can add the #includes, but you’ll notice the compiler may give errors. That’s because you have to dig pretty deep in the Phonon documentation provided by Qt in order to find out how to use their moc system. So make sure you add:

Qt += phonon

to the line in your QCreator *.pro file before you compile your application.

So when it’s time to deploy, make sure when you distribute your Phonon-based application to copy these folders to be distributed with your final Windows self-executable (*.exe format), which can be found in your Qt 4.8.7 installation folder %Qt%/plugins/

/phonon_backend
/codecs

You’ll also need the following DLLs to be distributed too, so copy them from Qt installation folder %Qt%/bin/

-QtDBus4.dll
-QtXml4.dll
-phonon4.dll

So once these folders and files have been distributed with your Windows self-executable, you should be able to play basic media files such as WAV and AVI formats. Other formats like MPG, MP3, MP4, AAC, MIDI, WMV, MOV, OGG, FLV may require additional codecs and programming. But the only way you’ll know for sure is to test them. Otherwise stick with formats you know for sure Windows (or your target deployment operating system) supports.

Hope that helps!

Posted in Qt | Leave a comment

Upgrading to Qt 4.8.7 from Qt 4.8.5

Upgrading to Qt 4.8.7 on Windows

By Chongchen Saelee

I’m upgrading from Qt 4.8.5 to Qt 4.8.7. I’m also using QtCreator 2.8.0. This a step-by-step guide on how I successfully upgraded.

NOTE: Qt 4.8.7 requires newer minGW 64 compiler, so if you don’t install that correctly, it won’t work. Qt 4.8.7 SDK Installer does not come with minGW 64 compiler, so you have to download that separately. Continue reading

Posted in Qt | Leave a comment

Warning! Qt Can Damage Your Computer

Don’t get me wrong, I love Qt, but they do make the disclaimer when you download and use their software. Just note that unless you have money to burn, if you keep pushing the limits of your hardware and operating system, odds are Qt will make it all crash and burn. For example, I’ve been able to compile and run “simple” programs endlessly without a problem. But once I start experimenting with QTransform or other heavy image processing things, my harddrive goes on the fritz or memory issues or graphics card chugs. It’s just not worth it if I have to replace these hardware. Therefore, just to put it out there for the hobbyists who might be curious: DO NOT RISK HAVING TO REPLACE YOUR HARDWARE BY EXPERIMENTING WITH QTRANSFORM OR QIMAGE IF, that’s IF YOU’RE GOING TO PUSH THE SYSTEM WITH 3D PROCESSING.

Mind you, that’s only if you’re messing with 3D stuff. You can mess with QPixmap and QImage for 2D stuff, but don’t mess with QTransform or QImage when it comes to 3D. It’s just too brutal on my hardware. I think it has to do with the nature of how Qt is designed: to do everything as fast as possible. And I’m assuming that include “unsafe” methods. I recall working with DirectX a bit and that’s why Microsoft wants you to use their “safe” DirectX functions vs “unsafe”, even though unsafe methods may yield faster results.

And I’m developing on a Windows 7, Pentium i5 3.4GHz Quad Core processor, new hard drive, new RAM, the works. So just be extra careful and aware. It’s not maliciously designed, it’s like that for a reason. Machine cannot regulate itself and always needs human intervention.

Posted in Qt | Leave a comment

How To Embed Font in Qt Application Using QFontDatabase

You can embed a True Type font or Open Type font into your Qt application using QFontDatabase. You can link to an external font file or link to a font embedded as a resource.

First, make sure you include a reference to the QFontDatabase class:

#include <QFontDatabase>;

To link to an external font, do this:

QFontDatabase database;
int result = database.addApplicationFont("/path/to/font.tff");

Or for a more reliable way, embed the font as a resource. Create a Qt resource file and add a reference to the font file you want embedded. Then use the path to the embedded resource font:

QFontDatabase database;
int result = database.addApplicationFont(":/resource/path/to/font.tff");

If the returned integer is greater than -1, then the font has successfully loaded into the font database. It’s essentially storing the font in memory at the application’s runtime. You can check your operating system’s installed fonts and if the font hasn’t already been installed, that using QFontDatabase doesn’t install the font on your system. So this is a cool way of having specific fonts just for your Qt app without messing with the end-user’s fonts.

And to use the font, you would call it from the font database:

QFont f = database.font("myFont", "normal", 12);
myWidget.setFont(f);

Of course, be mindful of the font you choose for your app. As graphic designers, we are taught that for digital screens, you want to use sans-serif fonts (vs serif fonts for print). There needs to be good whitespace. Since users will be staring at the fonts for long periods of time, it needs to look nice and balanced overall. Then there’s also the issue of visual consistency and compatibility across operating systems. In this case, you don’t have to embed a custom font, but make sure you choose a web-safe font.

Posted in Qt | Leave a comment