[SOLVED] Barcode example that doesn't work in Qt 5
-
I'm trying to develop a Qt application that writes and reads barcodes. After googling a lot, I came across with this "example":http://www.qtcentre.org/wiki/index.php?title=EAN-13_Barcode_class but after changing some includes in Qt Creator 5.2, It doesn't work.
What do I have to do? How can I do so that it works? Thanks in advance.
-
Hi,
Please provide more details: What do you mean by "it doesn't work"? What error messages do you get?
-
Simply I try to replicate that example in Qt Creator. I work on Qt 5.2 and Windows XP. Name of my project ean13 and I get the following output:
18:26:41: Starting: "E:\Qt\Qt5.2.1\Tools\mingw48_32\bin\mingw32-make.exe"
E:/Qt/Qt5.2.1/Tools/mingw48_32/bin/mingw32-make -f Makefile.Release
mingw32-make[1]: Entering directory 'E:/Qt/laboratorio/build-ean13-Desktop_Qt_5_2_1_MinGW_32bit-Release'
g++ -c -pipe -fno-keep-inline-dllexport -O2 -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_NO_DEBUG -DQT_CORE_LIB -I..\ean13 -I"....\Qt5.2.1\5.2.1\mingw48_32\include" -I"....\Qt5.2.1\5.2.1\mingw48_32\include\QtCore" -I"release" -I"." -I"....\Qt5.2.1\5.2.1\mingw48_32\mkspecs\win32-g++" -o release\ean13.o ..\ean13\ean13.cpp
g++ -Wl,-s -Wl,-subsystem,console -mthreads -o release\ean13.exe release/main.o release/ean13.o release/drawwidget.o release/moc_drawwidget.o -LE:\Qt\Qt5.2.1\5.2.1\mingw48_32\lib -lQt5Core
release/main.o:main.cpp:(.text.startup+0x4f): undefined reference to_imp___ZN7QWidget4showEv' release/ean13.o:ean13.cpp:(.text+0x33c0): undefined reference to
_imp___ZN8QPainter4saveEv'
release/ean13.o:ean13.cpp:(.text+0x3459): undefined reference to_imp___ZN8QPainter11setViewportERK5QRect' release/ean13.o:ean13.cpp:(.text+0x34ce): undefined reference to
_imp___ZN8QPainter9setWindowERK5QRect'
release/ean13.o:ean13.cpp:(.text+0x34e1): undefined reference to_imp___ZNK8QPainter6windowEv' release/ean13.o:ean13.cpp:(.text+0x34e6): undefined reference to
_imp___ZN6QColorC1EN2Qt11GlobalColorE'
release/ean13.o:ean13.cpp:(.text+0x3518): undefined reference to_imp___ZN8QPainter8fillRectERK5QRectRK6QColor' release/ean13.o:ean13.cpp:(.text+0x3542): undefined reference to
_imp___ZNK8QPainter6deviceEv'
release/ean13.o:ean13.cpp:(.text+0x3584): undefined reference to_imp___ZN8QPainter13setRenderHintENS_10RenderHintEb' release/ean13.o:ean13.cpp:(.text+0x35d2): undefined reference to
_imp___ZN5QFontC1ERK7QStringiib'
release/ean13.o:ean13.cpp:(.text+0x3616): undefined reference to_imp___ZN5QFont13setPointSizeFEd' release/ean13.o:ean13.cpp:(.text+0x362b): undefined reference to
_imp___ZN8QPainter7setFontERK5QFont'
release/ean13.o:ean13.cpp:(.text+0x3634): undefined reference to_imp___ZN8QPainter6setPenEN2Qt8PenStyleE' release/ean13.o:ean13.cpp:(.text+0x366b): undefined reference to
_imp___ZN8QPainter6setPenERK6QColor'
release/ean13.o:ean13.cpp:(.text+0x367b): undefined reference to_imp___ZN6QBrushC1Ev' release/ean13.o:ean13.cpp:(.text+0x368f): undefined reference to
_imp___ZN6QBrush8setStyleEN2Qt10BrushStyleE'
release/ean13.o:ean13.cpp:(.text+0x36b7): undefined reference to_imp___ZN6QBrush8setColorERK6QColor' release/ean13.o:ean13.cpp:(.text+0x36cc): undefined reference to
_imp___ZN8QPainter8setBrushERK6QBrush'
release/ean13.o:ean13.cpp:(.text+0x3749): undefined reference to_imp___ZN8QPainter12boundingRectERK5QRectiRK7QString' release/ean13.o:ean13.cpp:(.text+0x3841): undefined reference to
_imp___ZN8QPainter9drawRectsEPK6QRectFi'
release/ean13.o:ean13.cpp:(.text+0x386a): undefined reference to_imp___ZN8QPainter9translateERK7QPointF' release/ean13.o:ean13.cpp:(.text+0x3a01): undefined reference to
_imp___ZN8QPainter7restoreEv'
release/ean13.o:ean13.cpp:(.text+0x3a76): undefined reference to_imp___ZN8QPainter12boundingRectERK6QRectFiRK7QString' release/ean13.o:ean13.cpp:(.text+0x3b9e): undefined reference to
_imp___ZN8QPainter9translateERK7QPointF'
release/ean13.o:ean13.cpp:(.text+0x3bef): undefined reference to_imp___ZN8QPainter8drawTextERK6QRectFiRK7QStringPS0_' release/ean13.o:ean13.cpp:(.text+0x3d92): undefined reference to
_imp___ZN6QBrushD1Ev'
release/ean13.o:ean13.cpp:(.text+0x3d9f): undefined reference to_imp___ZN5QFontD1Ev' release/ean13.o:ean13.cpp:(.text+0x403e): undefined reference to
_imp___ZN6QBrushD1Ev'
release/ean13.o:ean13.cpp:(.text+0x404b): undefined reference to_imp___ZN5QFontD1Ev' release/ean13.o:ean13.cpp:(.text+0x407d): undefined reference to
_imp___ZN5QFontD1Ev'
Makefile.Release:82: recipe for target 'release\ean13.exe' failed
e:/qt/qt5.2.1/tools/mingw48_32/bin/../lib/gcc/i686-w64-mingw32/4.8.0/../../../../i686-w64-mingw32/bin/ld.exe: release/ean13.o: bad reloc address 0x20 in section `.text$_ZN7QStringD1Ev[__ZN7QStringD1Ev]'
collect2.exe: error: ld returned 1 exit status
mingw32-make[1]: Leaving directory 'E:/Qt/laboratorio/build-ean13-Desktop_Qt_5_2_1_MinGW_32bit-Release'
makefile:34: recipe for target 'release' failed
mingw32-make[1]: *** [release\ean13.exe] Error 1
mingw32-make: *** [release] Error 2
18:26:51: The process "E:\Qt\Qt5.2.1\Tools\mingw48_32\bin\mingw32-make.exe" exited with code 2.
Error while building/deploying project ean13 (kit: Desktop Qt 5.2.1 MinGW -
-
Please provide the information that tilsitt requested.
Also, try this: Delete the folders E:/Qt/laboratorio/build-ean13-Desktop_Qt_5_2_1_MinGW_32bit-Release and E:/Qt/laboratorio/build-ean13-Desktop_Qt_5_2_1_MinGW_32bit-Debug. Then, compile again.
-
Sorry for my delay!. And Thanks so much for your disposition. Here I put what tilsitt requested (I only change some includes and the code is the same as in the example):
ean13.pro
@#-------------------------------------------------Project created by QtCreator 2014-09-12T15:26:13
#-------------------------------------------------
QT += core
QT -= gui
TARGET = ean13
CONFIG += console
CONFIG -= app_bundleTEMPLATE = app
SOURCES += main.cpp
ean13.cpp
drawwidget.cppHEADERS +=
ean13.h
drawwidget.h
@drawwidget.h
@#ifndef DRAWWIDGET_H
#define DRAWWIDGET_H#include <QtWidgets/QWidget>
class DrawWidget : public QWidget
{
Q_OBJECT
same code in the example
@ean13.h
@#ifndef EAN13_H
#define EAN13_H#include <QtGlobal>
#include <QStringList>
#include <QtGui/QImage>same code in the example
@drawwidget.cpp
@#include <QtGui/QtGui>
#include "drawwidget.h"
#include "ean13.h"DrawWidget::DrawWidget(QWidget *parent)
: QWidget(parent)
{same code in the example
@ean13.cpp
@#include <QtCore>
#include <QDebug>
#include <QtGui/QImage>
#include <QtGui/QPainter>
#include "ean13.h"same code in the example
@main.cpp
@#include <QCoreApplication>
#include "drawwidget.h"int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
DrawWidget w;
w.show();return a.exec();
}
@ -
You're using QWidget in your code, but you're compiling your code without gui and widgets modules. I guess your .pro file and you main.cpp were generated with QtCreator using the console application template? Remove the line 9 in the project file which disable the gui module. In the line 7, add gui and widgets in the QT variable to enable the modules. In your main.cpp file, change the QCoreApplication to QApplication.