Wednesday, February 8, 2012

Error: QIODevice was not declared in this scope


Many may encounter similar errors like this. QMap does not name  a type;ISOC++  forbids declaration of QThread with no type;and so on.

How to correct these?

These occur due to the fact that proper header files are not included in the header files of your project.
Just search the terms in the errors like QThread , QMap etc in Qt Assistant and find the header files;include those in your header files where the errors occur like #include<qthread.h>, #include<qmap.h> and so on.

The error QIODevice was not declared in this scope can also be alleviated by #include<qiodevice.h> in the header file.
Error : QtCore : No such file or directory


This error occurs in a Qt project when #include <QtCore> is used in the header files of your project. QtCore is a part of Qt 4  and not available for Qt 3.3.So inoredr to use Qtcore , Qt4 needs to be installed in your system. Qt 3.3 and Qt 4 can be available in the same system ; i.e these 2 can co-exist in the same system. Even if Qt 4 is installed in your system , the error occurs.

The question is , how to correct this?

When you use the file QtCore in your header files , you need to set the path in your project directory. To know the present directory path , go to your project directory and just type echo $QTDIR in command prompt , press enter. you can see its default set to qt3.3. So just type these 3 in command prompt after you change to your project directory.

i)

ii)

iii)

Now again type echo $QTDIR , you can see the path settings now point to qt4.

After this, instead of qmake to create the Makefile , type qmake-qt4 <.pro file>. Also , include a statement QT+= core in your .pro file.

The error will disappear!!!

Thursday, February 2, 2012

Using ffmpeg library in a Qt project


ffmpeg is a wonderful library for creating video applications or even general purpose utilities. ffmpeg takes care of all the hard work of video processing by doing all the decoding, encoding, muxing and demuxing for you.

The improper use of ffmpeg library in  a Qt project result in errors like "undefined reference to av_register_all";"undefined reference to av_free()" and so on. So

How to use ffmpeg library in a Qt project?

For reliable use of ffmpeg library in a Qt project , 3 things are essential:

i) Qt project file should include ffmpeg library paths

ii) Qt project file should include ffmpeg include paths (it worked for me without this )

iii) Link the specific ffmpeg libraries that you are gonna use.

Ok....Now how to do this?

open your Qt project file project.pro, include in it

INCLUDEPATH += /usr/local/include/ (where your ffmpeg libraries are)

LIBS+= -lavcodec \
           
             -lavutil \

           -lswscale \

         -lavformat  (exclude those libraries you don't use)

library paths may also be included like -LC:/usr/local/ffmpeg-0.8.5/libavcodec.so so on....It is not compulsory.

Also include a statement

QMAKE_CXXFLAGS  += -D__STDC_CONSTANT_MACROS in your .pro file.