Qt 5.2 cannot get qWait function to work - c++

I've got a header file with the following include:
#include <QtTest/QtTest>
I am trying to use the following line to generate a non-blocking wait in my main window:
QTest::qWait(1000 - ui->speedDial->value());
I receive the following error:
mainwindow.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) void __cdecl QTest::qSleep(int)" (__imp_?qSleep#QTest##YAXH#Z) referenced in function "void __cdecl QTest::qWait(int)" (?qWait#QTest##YAXH#Z)
Can anyone help me understand what I am doing wrong, or provide an alternative method? These lines are independent of other code.

It works fine for me. Check this example which is a modified version of the Qt Test official documentation example:
tutorial1.pro:
SOURCES = testqstring.cpp
CONFIG += qtestlib
# install
target.path = $$[QT_INSTALL_EXAMPLES]/qtestlib/tutorial1
sources.files = $$SOURCES *.pro
sources.path = $$[QT_INSTALL_EXAMPLES]/qtestlib/tutorial1
INSTALLS += target sources
symbian {
TARGET.UID3 = 0xA000C60B
include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
}
maemo5: include($$QT_SOURCE_TREE/examples/maemo5pkgrules.pri)
symbian: warning(This example might not fully work on Symbian platform)
maemo5: warning(This example might not fully work on Maemo platform)
simulator: warning(This example might not fully work on Simulator platform)
testqstring.cpp:
#include <QtTest/QtTest>
#include <QDebug>
class TestQString: public QObject
{
Q_OBJECT
private slots:
void toUpper();
};
void TestQString::toUpper()
{
QString str = "Hello";
QTest::qWait(2000);
QCOMPARE(str.toUpper(), QString("HELLO"));
}
QTEST_MAIN(TestQString)
#include "testqstring.moc"

Related

Unresolved External Symbol while trying to use bit7z library C++ / Qt

I've been trying to install and properly link bit7z into my C++ code as I have to do a task for my internship which concludes in automatically zipping a certain directory and sending the zip-file out as an email. Right now the email is not interesting to me as I can't even get the base program. I just keep getting the Linker Error 2019 and I don't know what to do anymore. I'll provide as much info as I can.
I use Visual Studio 2019.
My .pro file:
TEMPLATE = app
TARGET = aixLogger
DESTDIR = ./Debug
CONFIG += debug console
DEPENDPATH += .
MOC_DIR += .
OBJECTS_DIR += debug
UI_DIR += GeneratedFiles
RCC_DIR += GeneratedFiles
LIBS += -D:/local/aretz/Programmierung/git-workplace/aixLogger/Dependencies/bit7z/lib -lbit7z
INCLUDEPATH += D:/local/aretz/Programmierung/git-workplace/aixLogger/Dependencies/bit7z/include
include(aixLogger.pri)
My .h
#pragma once
#include <qwidget.h>
#include <qobject.h>
#include <bit7z.hpp>
class AIXLogger : public QWidget
{
Q_OBJECT
public slots:
public:
void CompressDir();
void Execute();
};
My .cpp
#include <QCoreApplication>
#include <string>
#include <iostream>
#include <filesystem>
#include <bit7z.hpp>
#include "main.h"
#include "bitcompressor.hpp"
namespace fs = std::filesystem;
using namespace bit7z;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
std::string path = "C:/Users/aretz/Downloads/test";
for (const auto& entry : fs::directory_iterator(path))
std::cout << entry.path() << std::endl;
//return a.exec();
}
void AIXLogger::CompressDir() {
try {
Bit7zLibrary lib{ L"C:/Program Files/7-Zip/7z.dll" };
//BitCompressor compressor{ lib, BitFormat::Zip };
std::vector< std::wstring > files = { L"aretz/downloads/test/test1.txt", L"aretz/downloads/test/test1.txt" };
//Zip Archiv erstellen
//compressor.compress(files, L"output_archive.zip");
//Directory zippen
//compressor.compressDirectory(L"dir/path/", L"dir_archive.zip");
}
catch (const BitException& ex) {
//irgendwas mit &ex machen
}
}
void AIXLogger::Execute() {
CompressDir();
}
I'm also adding pictures of the properties I changed.
Additional DependenciesAdditional Library DirectoriesAdditional Include Directories
EDIT: Here is the actual Error I'm getting with just the line "Bit7zLibrary lib {L"C:/Program Files/7-Zip/7z.dll" };:
Error LNK2019 unresolved external symbol "public: __thiscall bit7z::Bit7zLibrary::Bit7zLibrary(class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > const &)" (??0Bit7zLibrary#bit7z##QAE#ABV?$basic_string#_WU?$char_traits#_W#std##V?$allocator#_W#2##std###Z) referenced in function "public: void __thiscall AIXLogger::CompressDir(void)" (?CompressDir#AIXLogger##QAEXXZ) aixLogger D:\local\aretz\Programmierung\git-workplace\aixLogger\main.obj 1
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "public: virtual __thiscall bit7z::Bit7zLibrary::~Bit7zLibrary(void)" (??1Bit7zLibrary#bit7z##UAE#XZ) referenced in function "public: void __thiscall AIXLogger::CompressDir(void)" (?CompressDir#AIXLogger##QAEXXZ) aixLogger D:\local\aretz\Programmierung\git-workplace\aixLogger\main.obj 1
The problem you're having is that the linker cannot find the bit7z static library.
By default, the bit7z library is built to bit7z\bin\$(PlatformShortName)\, where $(PlatformShortName) is either x86 or x64 according to your target architecture.
However, you specified a different library directory (bit7z\lib\), which is wrong (unless you changed the directory where you output the built library).
You can fix it by changing the path to $(SolutionDir)Dependencies\bit7z\bin\$(PlatformShortName)\.
Also, please note that, on x86, the default library name is just bit7z.lib, while on x64 is bit7z64.lib.

LNK2019 on constructor with QGraphicsView subclass

I may be missing something obvious, but I can't get rid of a linking error in my Qt user interface.
I've isolated the part that's causing trouble. Basically, I'm implementing a subclass of QGraphicsView to display an interactive overhead map. For some reason, I can't get the constructor to be resolved.
OverheadMap.h :
#ifndef OVERHEADMAP_H
#define OVERHEADMAP_H
#include <QGraphicsView>
class OverheadMap : public QGraphicsView {
Q_OBJECT
public:
OverheadMap();
};
#endif // OVERHEADMAP_H
OverheadMap.cpp :
#include "OverheadMap.h"
OverheadMap::OverheadMap() {
// Body
}
main.cpp :
#include "OverheadMap.h"
int main(int argc, char *argv[])
{
OverheadMap *map = new OverheadMap();
}
LNK2019 :
main.obj:-1: error: LNK2019: unresolved external symbol "public: __thiscall OverheadMap::OverheadMap(void)" (??0OverheadMap##QAE#XZ) referenced in function _main
I can without any trouble use QtCreator's auto-completion with OverheadMap, and I have done a similar subclass implementation of a QFrame that's working, so I doubt there's a syntax error here.
What am I missing?
Thanks.
This code works just fine for me.
So, the solution is that you have to re-run qmake because based on your comments, you modified the project structure without telling that to qmake.
You need to call your base class's constructor
OverheadMap::OverheadMap() : QGraphicsView()
{
// Body
}

C++/Qt: Just a LNK2019 and I don't know why

I have one of this unpopular LNK2019-errors in my project. Perhaps anyone can help me?
That's my header file:
#ifndef ELIST_H
#define ELIST_H
#include <QTableWidget>
class EList : public QTableWidget{
Q_OBJECT
public:
explicit EList(QWidget *parent = 0){}
~EList(){}
};
#endif // ELIST_H
and that's another cpp-file, where I want to create an object of EList in method do():
#include "elist.h"
#include "a.h"
void A::do(){
EList* el = new EList;
}
But then I get this LNK2019 error message:
a.obj:-1: Error:LNK2019: ""public: __cdecl EList::EList(class QWidget *)" (??0EList##QEAA#PEAVQWidget###Z)" in function ""public: __cdecl A::A(class QWidget *)" (??0A##QEAA#PEAVQWidget###Z)".
What did I wrong or what I have to do? I have insert all files/classes I could imagine but it did not show any effect.
EDIT: Here you can see my pro-File:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = A
TEMPLATE = app
SOURCES += main.cpp\
a.cpp \
elist.cpp
HEADERS += a.h \
elist.h
FORMS += a.ui
RESOURCES += \
ListViewIcon.qrc
And if I change Compiler (Qt 5.1 MSVC 2012) to Microsoft (Microsoft Visual C++ Compiler 11.0), all files will compiled...
With C++ code, you generally can't mix-and-match compilers. Whatever C++ compiler was used to build Qt is what you should be using to build your application. You've basically answered your own question :)

boost function and bind external symbol

I need to use bind and function in my program.But unfortunately vs2010 can't link my program.
I used following example from boost::bind documentation
#include <boost\bind.hpp>
#include <boost\function.hpp>
#include <functional>
class button
{
public:
boost::function<void()> onClick;
};
class player
{
public:
void play();
void stop();
};
button playButton, stopButton;player thePlayer;
void connect()
{
playButton.onClick = boost::bind(&player::play, &thePlayer);
stopButton.onClick = boost::bind(&player::stop, &thePlayer);
}
void main(int argc, char* argv[])
{
connect();
}
Error 1 error LNK2019: unresolved external symbol "public: void __thiscall player::stop(void)" (?stop#player##QAEXXZ) referenced in function "void __cdecl connect(void)" (?connect##YAXXZ)
i have tried the newest 32 and 64 verion of BoostPro and followed this tutorial http://www.youtube.com/watch?v=5AmwIwedTCM.All but vs still produces same error...
VS2010 project setting include/lib path
https://dl.dropbox.com/u/47585151/vs.png
however when I turned on
Linker->General->ShowProgress ->For Libraries Searched (/VERBOSE:Lib)
i noticed that VS is searching only for these libraries which are defined in
Linker->Input->Additional Dependencies
http://pastebin.com/BCpEt8Zq
is it possible to check which .lib boost need for boost::bind and boost::function under vs2010?
This problem has nothing to do with any boost library (both are header-only). Try to simply call start and stop from within connect and you should get the same error. Read it carefully, it tells you what is missing.

Qt: Linker error with QVERIFY (Qt Unit Tests)

Basically I am following the basic example here. My .pro file contains QT += core network qtestlib. [Solved] testlib instead of typo qtestlib
When I include QVERIFY, It get the following linker error:
testwaypointlist.obj:-1: error: LNK2019: unresolved external symbol "bool __cdecl
QTest::qVerify(bool,char const *,char const *,char const *,int)"
(?qVerify#QTest##YA_N_NPBD11H#Z) referenced in function "private: void __thiscall
TestWaypointList::fillWaypoints(void)" (?fillWaypoints#TestWaypointList##AAEXXZ)
What files do I miss to link? Without QVERIFY the linker error disappears.
Header file:
#include <QObject>
#include <QtTest/QtTest>
#include "waypointlist.h"
//
// Testing the waypoint list
//
class TestWaypointList : public QObject
{
Q_OBJECT
private:
WaypointList _waypointList;
public:
explicit TestWaypointList(QObject *parent = 0);
private slots:
void fillWaypoints();
};
cpp:
//
// Fill the waypoint list
//
void TestWaypointList::fillWaypoints()
{
_waypointList = WaypointList();
.....
for (int i=0; i < TESTWPLISTCOUNT; i++) {
.....
TestWaypointList::_waypointList.updateOrAppend(id, timeframe);
}
QVERIFY(TestWaypointList::_waypointList.count() == 1); // causing the linker error
}
In your .pro file, you need to change QT += qtestlib to QT += testlib (note the absence of a "q").
Of note, you used to be able to do this: CONFIG += qtestlib, but according to the comment on this page, this is no longer the recommended way of linking to the test library.