I'm new to Code::Blocks (nice IDE!) and to Qt with C++ (been using PyQt, which works wonderfully)
I have a test project - here's the code (generated by code::blocks wizard):
#include <QApplication>
#include <QFont>
#include <QPushButton>
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QPushButton quit("Quit");
quit.resize(75, 30);
quit.setFont(QFont("Times", 18, QFont::Bold));
QObject::connect(&quit, SIGNAL(clicked()), &app, SLOT(quit()));
quit.show();
return app.exec();
}
I BELIEVE I have the search path for Qt4 configured correctly in code::blocks, but when I try to run this code I get the below listed errors - so obviously I'm missing something - either my paths are in correct or my installation is corrupt. For my Qt installation I used Qt_SDK_Win_offline_v1_1_2_en.exe, found on the Qt website - installed the entire Qt SDK in D:, so the root path for the Qt installation is D:\QtSDK..
Any help on how to fix this configuration would be appreciated - I am excited about using Qt with C++ after fighting with Win32s/MFC/.NET etc etc for so many years....
Errors:
||=== QtTest, Debug ===|
obj\Debug\main.o||In function `main':|
E:\ResourceBrowse\QtTest\main.cpp|7|undefined reference to >`imp__ZN12QApplicationC1ERiPPci'|
E:\ResourceBrowse\QtTest\main.cpp|9|undefined reference to `imp__ZN11QPushButtonC1ERK7QStringP7QWidget'|
E:\ResourceBrowse\QtTest\main.cpp|12|undefined reference to `imp__ZN5QFontC1ERK7QStringiib'|
E:\ResourceBrowse\QtTest\main.cpp|12|undefined reference to `imp__ZN7QWidget7setFontERK5QFont'|
E:\ResourceBrowse\QtTest\main.cpp|12|undefined reference to `imp__ZN5QFontD1Ev'|
E:\ResourceBrowse\QtTest\main.cpp|12|undefined reference to `imp__ZN5QFontD1Ev'|
E:\ResourceBrowse\QtTest\main.cpp|14|undefined reference to `imp__Z13qFlagLocationPKc'|
E:\ResourceBrowse\QtTest\main.cpp|14|undefined reference to `imp__Z13qFlagLocationPKc'|
E:\ResourceBrowse\QtTest\main.cpp|14|undefined reference to `imp__ZN7QObject7connectEPKS_PKcS1_S3_N2Qt14ConnectionTypeE'|
E:\ResourceBrowse\QtTest\main.cpp|18|undefined reference to `imp__ZN12QApplication4execEv'|
E:\ResourceBrowse\QtTest\main.cpp|18|undefined reference to `imp__ZN11QPushButtonD1Ev'|
E:\ResourceBrowse\QtTest\main.cpp|18|undefined reference to `imp__ZN11QPushButtonD1Ev'|
E:\ResourceBrowse\QtTest\main.cpp|18|undefined reference to `imp__ZN12QApplicationD1Ev'|
E:\ResourceBrowse\QtTest\main.cpp|18|undefined reference to _imp___ZN12QApplicationD1Ev'|
obj\Debug\main.o||In functionQString':|
D:\QtSDK\Desktop\Qt\4.7.3\msvc2008\include\QtCore\qstring.h|426|undefined reference to _imp___ZN7QString16fromAscii_helperEPKci'|
obj\Debug\main.o||In function~QString':|
D:\QtSDK\Desktop\Qt\4.7.3\msvc2008\include\QtCore\qstring.h|883|undefined reference to `imp__ZN7QString4freeEPNS_4DataE'|
obj\Debug\main.o:D:\QtSDK\Desktop\Qt\4.7.3\msvc2008\include\QtGui\qwidget.h|1001|undefined reference to
`imp__ZN7QWidget6resizeERK5QSize'|
||=== Build finished: 17 errors, 0 warnings ===|
Related
I'm following Qt's Qt for Beginners tutorial and for some reason I am getting a compilation error when trying to build the simplest example of a gui. It looks like it's failing on button creation because it thinks that qcolor is unimplemented(?). I just downloaded the latest Qt 5.14.0 and installed it today, so it's possible that something happened during the install?
This is what my project layout looks like:
build-new_qt_project-Desktop_Qt_5_14_0_GCC_64bit-Debug:
Makefile
new_qt_project:
main.cpp
new_qt_project.pro
main.cpp:
#include <QApplication>
#include <QPushButton>
int main(int argc, char **argv)
{
QApplication app (argc, argv);
QPushButton button ("Hello world !");
button.show();
return app.exec();
}
new_qt_project.pro:
TEMPLATE = app
TARGET = new_qt_project
QT = core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
SOURCES += main.cpp
And this is the output from trying to make it:
In file included from ../../Qt5.14.0_2/5.14.0/gcc_64/include/QtGui/qpixmap.h:45:0,
from ../../Qt5.14.0_2/5.14.0/gcc_64/include/QtGui/qicon.h:46,
from ../../Qt5.14.0_2/5.14.0/gcc_64/include/QtWidgets/qabstractbutton.h:44,
from ../../Qt5.14.0_2/5.14.0/gcc_64/include/QtWidgets/qpushbutton.h:44,
from ../../Qt5.14.0_2/5.14.0/gcc_64/include/QtWidgets/QPushButton:1,
from ../new_qt_project/main.cpp:2:
../../Qt5.14.0_2/5.14.0/gcc_64/include/QtGui/qcolor.h: In constructor ‘constexpr QColor::QColor(int, int, int, int)’:
../../Qt5.14.0_2/5.14.0/gcc_64/include/QtGui/qcolor.h:79:18: sorry, unimplemented: use of the value of the object being constructed in a constant expression
0) {}
^
make: *** [main.o] Error 1
I'm using the default (detected) kit to build it and it has the C++ compiler pointing to the one in /usr/bin, so I think that is correct. Is there something additional I've missed?
I think this is the problem:
Qt bug
update your gcc. up to 4.9 !!!
i had this problem and i used gcc 4.8 and after update it to gcc-7 it is now correct
I recently installed VlcQt libary for ubuntu 16.04, but when I try to use it, all i get is undefined reference to 'some_function()'.
Currently I am trying to expose video player to QML.
Main.cpp
#include <QGuiApplication>
#include <VLCQtCore/Common.h>
#include <VLCQtQml/QmlVideoPlayer.h>
#include "Controller.h"
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
VlcCommon::setPluginPath(app.applicationDirPath() + "plugins");
VlcQmlVideoPlayer::registerPlugin();
Controller controller;
QQuickWindow *quickWindow = qobject_cast<QQuickWindow *>(controller.view());
quickWindow->show();
return app.exec();
}
When I am trying to include libaries, Qt intellisense is detecting that this libary exists.
What am I doing wrong?
Thank you for your help!
//Edit:
I installed it via their repository:
add-apt-repository ppa:ntadej/tano
apt-get install libvlc-qt-core2 libvlc-qt-widgets2 libvlc-qt-dbg libvlc-qt-dev
//Edit:
This is how I add libs in .pro file, already tried INCLUDEPATH too
LIBS += -lvlccore -lvlc
I'm trying to get a simple hello world example running, and already needed some time to figure out what includes to use
Now I verified the include paths, the QApplication should actually be there, but it throws the above error. For clarity my code:
#include <QtWidgets/QApplication>
#include <QtWidgets/QPushButton>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QPushButton *button = new QPushButton("Hello world!");
button->show();
return app.exec();
}
I tried compiling using first qmake -project, then qmake and finally make and then got the following errors:
qt_hello_world.o: In function 'main':
undefined reference to QApplication::QApplication(int&, char**, int)
qt_hello_world.cpp: undefined reference to QPushButton::QPushButton(QString const&, QWidget*)
qt_hello_world.cpp: undefined reference to QWidget::show()
qt_hello_world.cpp: undefined reference to QApplication::exec()
qt_hello_world.cpp: undefined reference to QApplication::~QApplication()
qt_hello_world.cpp: undefined reference to QApplication::~QApplication()
The Makefile created by qmake contains the correct include path to the qt5 directory which contains the QtWidgets/QApplication, the QApplication file just includes the qapplication.h header that contains the actual class QApplication.
The tutorial https://wiki.qt.io/Qt_for_Beginners is fully updated so you must modify it. Change to:
TEMPLATE = app
TARGET = callboot-ui.exe
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
HEADERS +=
SOURCES += main.cpp
TL; DR;
In the case of #jww it has an error in the following line of the .pro:
greaterThan(QT_MAJOR_VERSION, 5): QT += core gui widgets
The error is caused because greaterThan(QT_MAJOR_VERSION, 5) verifies that the major version of Qt is greater than 5 to add sub-modules, but the latest version of Qt is 5.13.2 is not greater than 5, so it is not linked the modules causing the error shown.
In the tutorial greaterThan(QT_MAJOR_VERSION, 4): QT += widgets is used to support .pro so that it can be compiled for Qt4 and Qt5 since in the latter the widgets moved to a new sub-module called widgets.
I'm trying to use CMU Sphinx in Qt. I've installed pocketsphinx and sphinxbase, and made a project in Qt, and added the following code to the main.cpp file:
#include <pocketsphinx.h>
#define MODELDIR "/usr/local/share/pocketsphinx/model"
int main(int argc, char* argv[])
{
ps_decoder_t *ps = nullptr;
cmd_ln_t *config = nullptr;
config = cmd_ln_init(NULL, ps_args(), TRUE,
"-hmm", MODELDIR "/en-us/en-us",
"-lm", MODELDIR "/en-us/en-us.lm.bin",
"-dict", MODELDIR "/en-us/cmudict-en-us.dict",
NULL);
}
I've also added the following lines to the .pro file:
INCLUDEPATH += /usr/local/include/sphinxbase
INCLUDEPATH += /usr/local/include/pocketsphinx
When I try building, I get the following errors:
undefined reference to ps_args
undefined reference to cmd_ln_init
I'm on Debian 8. What have I missed?
Okay, so this might seem silly, but I finally solved the issue, and I hope this helps anyone with similar errors in Qt in the future.
The way to solve it is to right-click anywhere in the editor, and click Add Library, and then select System Library. I then entered the library name, which in my case was pocketsphinx. I repeated it for sphinxbase. Then go to Build - Run qmake, and then build.
It's the first time I make mock object in QT. I'm trying using Gmock, but I don't know how to using it.
Now, I create project TestGmock (QT Application) in QT, and I copy include folder in gmock-1.7.0 ( download it from https://code.google.com/) to TestGmock project directory ( and the same with gtest ). In class main :
#include <QCoreApplication>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
int main(int argc, char *argv[])
{
testing::InitGoogleMock (&argc, argv);
return RUN_ALL_TESTS();
}
But error :
C:\Qt\Qt5.2.1\Tools\QtCreator\bin\TestGmock\main.cpp:6: error: undefined reference to `testing::InitGoogleMock(int*, char**)'
C:\Qt\Qt5.2.1\Tools\QtCreator\bin\TestGmock\gtest\gtest.h:2288: error:undefined reference to `testing::UnitTest::GetInstance()'
C:\Qt\Qt5.2.1\Tools\QtCreator\bin\TestGmock\gtest\gtest.h:2288: error:undefined reference to `testing::UnitTest::Run()' collect2.exe:-1:
error: error: ld returned 1 exit status
Please help me using gmock and gtest in QT.
This error is caused the fact, that Qt Creator couldn't find Gmock library. There is no need to put it in your project (or Qt installation) directory, but you should add INCLUDEPATH and LIBS options in .pro file. Look at Adding external library into Qt Creator project.