SYSTEMTIME in qt - c++

I am a bit stuck at the moment with a little sample project that I would like to run to test some cryptology that I want to use in a main project.
Basically I am using the latest Qt Creator and I have created a simple window dialog. Furthermore, I would like to test the PBKDF2 implementation through CkCrypt2
So what I have done is downloading the X64 version of the library and added it to my project folder. I then told my Qt project to use an external library, the final .pro file looks like this:
#-------------------------------------------------
#
# Project created by QtCreator 2013-06-09T18:09:44
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = crypt2test
TEMPLATE = app
SOURCES += main.cpp\
m
ainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/libs/ -lChilkatDbgDll_x64
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/libs/ -lChilkatDbgDll_x64d
else:unix: LIBS += -L$$PWD/libs/ -lChilkatDbgDll_x64
INCLUDEPATH += $$PWD/include
DEPENDPATH += $$PWD/include
I can successfully load the library but I cannot start the application.
My mainwindow.cpp looks like this:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "CkCrypt2.h"
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
CkCrypt2 crypt;
bool success;
success = crypt.UnlockComponent("Just some random text ");
if ( !success )
{
qDebug() << "Not successfully unlocking the library";
}
}
MainWindow::~MainWindow()
{
delete ui;
}
The error message I get in the compiler is:
c:\qt\qt5.0.2\tools\qtcreator\bin\crypt2test\include\CkString.h:127: error: C2061: syntax error : identifier 'SYSTEMTIME'
c:\qt\qt5.0.2\tools\qtcreator\bin\crypt2test\include\CkString.h:129: error: C2061: syntax error : identifier 'SYSTEMTIME'
C:\Qt\Qt5.0.2\Tools\QtCreator\bin\crypt2test\include\CkCrypt2.h:429: error: C2061: syntax error : identifier 'SYSTEMTIME'
Looking into the files I see:
void appendDateRfc822(SYSTEMTIME &sysTime);
void appendDateRfc822Gmt(SYSTEMTIME &sysTime);
// GETSIGNATURESIGNINGTIME_BEGIN
bool GetSignatureSigningTime(int index, SYSTEMTIME &outSysTime);
// GETSIGNATURESIGNINGTIME_END
Okay, so it is complaining about the SYSTEMTIME construct. So I look up the error C2061
Basically it says:
The compiler found an identifier where it wasn't expected. Make sure
that identifier is declared before you use it.
Which makes sense, so I look up the SYSTEMTIME and try to do :
#include <windows.h>
But that leads to many more errors in the windows.h file itself.
I use the MS Visual C++ compiler in Qt. Even though I use qmake. I am very new to this and I do not understand it all yet. Furthermore, I have no idea how to fix this, because including the windows.h does not help.
What seems to be the problem here ? Is this an issue regarding my compiler or the constulation that I use a third party app which library is compiled with MS Visual C++ and I am now trying to use this on my Windows machine in Qt with a Windows Visual C++ compiler ?
For any help I am gratefully thankful!
EDIT1:
Actually, after a clean all and qmake and build project I have now different errors and none were found in the Windows.h as previously stated. Since there were so many I have made a screenshot: http://i.imgur.com/B8EoENB.png
EDIT2:
I have adjusted the library that I include. Before this I was using the multi-threaded library of CkCrypt in the Debug mode. I have now included the single realease library. Which is located in the same directory.
When including windows.h I got the errors that things were already defined. So I removed the line again. With this result: http://i.imgur.com/z415txR.png
This shows at the bottom that MSVCRT conflichts with other library. It mentions to use NODEFAULTLIB:library but I am not to sure how to do that. Will google and keep this up to date as I process.

Many years ago, Chilkat was originally developed for the Windows platform only, and used SYSTEMTIME for this reason. In the last 5 years (approx) Chilkat is cross-platform, and SYSTEMTIME no longer makes sense. To cope with the issue, there is a "SystemTime.h" header in the same directory as the CkCrypt2.h header file. You could include this to solve the problem. (However, if WIN32 is defined, you'll probably need to edit SystemTime.h to remove the #ifdef.)
In any case, the methods using SYSTEMTIME are going to be deprecated. For any method or property that uses SYSTEMTIME, there should be a newer alternative method/property that instead uses CkDateTime.
Finally, Chilkat will test with Qt so that for the next version, (hopefully) Qt out-of-the-box will compile without any pitfalls.

Related

How to get the CImg library working for Qt

I'm currently learning how to use Qt. I want to try out some simple image processing applications using Qt, and since I'm already familiar with CImg I want to use that. I guess it should be possible to do so, if not mark my question for deletion or something.
My question is: how to get CImg working for Qt? CImg is a header file. Lets say its located on my desktop. I import it using Qt creator 4.1.0, by using the "add existing file..." in the rightclick menu on the header folder. Then my menu looks like this:
.
It compiles when I add #include "CImg.h", but I can't use it, even when I'm trying to type using namespace cimg_library it will tell me that cimg_library doesn't exist. I also tried just creating a header file and copying the content of the CImg.h into it but then it simply fails to compile and the Qt Creator freezes.
Edit: I managed to make the situation a bit better by adding the header location to the include code (like this: #include "C:/Users/Marci/Desktop/CImg.h" )I can now "see" CImg related stuff in the dev environment, and it won't bother me with not finding the constructor for CImg or anything like that. However when I try to compile while using anything CImg related it will give me around 20 linker errors. (Error code: LNK2019) My .pro file looks like this:
#-------------------------------------------------
#
# Project created by QtCreator 2016-11-08T17:08:58
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = grayscale
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h \
C:/Users/Marci/Desktop/CImg.h
LIBS += -C:/Users/Marci/Desktop/ -CImg.h
FORMS += mainwindow.ui
Edit2: after implementing the changes that PeterT suggested in his comment my .pro file looks like this:
#-------------------------------------------------
#
# Project created by QtCreator 2016-11-08T17:08:58
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = grayscale
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h \
INCLUDEPATH += C:/Users/Marci/Desktop
FORMS += mainwindow.ui
And my mainwindow.cpp (in which i'm trying to create a CImg object) looks like this:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <CImg.h>
using namespace cimg_library;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
CImg<unsigned char> myimage(100,200);
}
MainWindow::~MainWindow()
{
delete ui;
}
The compiler errors i get are: error: C2871: 'cimg_library': a namespace with this name does not exist
error: C2065: 'CImg': undeclared identifier
error: C2062: type 'unsigned char' unexpected
I hope this is specific enough.
After I few months I figured it out. The problem lies in the fact, that CImg uses a windows .dll file for the visualizing functions of the class cimg_display. Since Qt is platform independent it doesnt like this. However you can make it work with an interesting trick. First you need to include the header file normally, in the project file. After that, whenever you actually #include it, you need to write the following macro:
#define cimg_display 0
In my understanding this makes it work, because the C and C++ compilers simply copy the content of the included file into the source. And thanks to the macro the compiler will ignore the class thats causing trouble for us.

How to embed SQLite into a C++ project

I'm trying to embed SQLite into my project. I have included the following files into a directory called lite : sqlite3.dll, sqlite3.h, and sqlite3.lib.
This is my project:
#include <stdio.h>
#include <lite/sqlite3.h>
int main(int argc, char* argv[])
{
sqlite3 *db;
char *zErrMsg = 0;
int rc;
rc = sqlite3_open("test.db", &db);
if( rc ){
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
return(0);
}else{
fprintf(stderr, "Opened database successfully\n");
}
sqlite3_close(db);
}
I get the following errors when I run the project:
:-1: error: cannot find -lsqlite3d
collect2.exe:-1: error: error: ld returned 1 exit status
What could I be doing wrong?
I'm working in Qt. This is my .pro file:
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/lite/ -lsqlite3
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/lite/ -lsqlite3d
else:unix: LIBS += -L$$PWD/lite/ -lsqlite3
INCLUDEPATH += $$PWD/lite
DEPENDPATH += $$PWD/lite
Since you are already using Qt why don't you use Qt SQL module? You are going to save a lot of pain, you will bypass this kind of linkage problems just by adding
QT += sql
to you Qt project file, and adding
#include <QtSql>
to you surce files. You'll have a lot of model-view classes that facilitate the integration of the database into your application UI.
This is the recommended way to use SQL in Qt applications, unless you have very very specific needs. You can have Qt use different SQL engines under the hood (SQLite, MySQL,...), but Qt will abstract all this for you.
Despite too late, there are a couple of issues here which I think were completely left out in this question, even though the workaround is practical ..
The error is quite clear .. linker could not find the "debug" version of the lib lsqlite3d which is so configured in qmake .pro file. either get the "debug" file of the lib, or remove this line from .pro
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/lite/ -lsqlite3d
This seems a common mistake when adding a library in Qt .. there is an option like :
Add "d" suffix for debug version
And this must be deselected when there is no debug version of the lib.
Second and the essence of this answer, since SQLite is written in C , the include
section is not correct and wont work; It must be corrected to be:
extern "C" {
#include <lite/sqlite3.h>
}
With these two issues corrected .. there should be no problem adding SQLite library, or, in general, any C library to Qt.
Practically with small code like SQLite, another option is to statically compile it with the project .. by just adding sqqlite3.h and sqlite3.c to the Qt project and removing the linkage to sqlite3.lib in .pro .. with the include section as updated.

Porting a Windows compiled QT application to Linux?

I created this simply application in Qt4 and would like to test it on RH Linux distro. The distro has both QtCore "Qt4" and Qt3 installed. I cannot add or delete any of these Qt versions, but would like to work with what's available.
I have an error compiling my windows based Qt program "Qt4" in Linux .
First question :
- How do I compile my compile in Linux without QT creator "only Qt libraries" are installed, what I did is get the .pro file from windows and typed qmake . , the errors are :
WARNING : Found potential symbol conflict of mainwindow.cpp (mainwwindow.cpp) in SOURCES
WARNING : Found potential symbol conflict of mainwindow.h (mainwwindow.cpp) in HEADERS
WARNING : Found potential symbol conflict of dialog.cpp (dialog.cpp) in SOURCES
WARNING : Found potential symbol conflict of dialog.h (dialog.h) in HEADERS
How can I modify qmake to specify the version of Qt
Thank you.
Below is my .pro file
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = TestTool
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
dialog.cpp
HEADERS += mainwindow.h \
dialog.h
FORMS += mainwindow.ui \
dialog.ui
The compilation error is :
Try using the Qt4 version of qmake explicitly:
/usr/lib64/qt4/bin/qmake -o Makefile TestTool.pro

QtCreator LNK2019 error with external library

I have a problem when I want to link a library to my Qt project.
When I try to include an external library (libnodave.lib) in Qt Creator and try to build it, the following error occurs.
main.obj:-1: Fehler: LNK2019: unresolved external symbol __imp_daveSetDebug referenced in function main
I'm pretty sure that I included all needed files in my project and the .pro file. I used the "Add Library" wizard to add the library.
After no success with Qt Creator, I created a minimal example with Visual Studio. When I include all the needed files to the VS project, I can build and run it without errors. So I think that there must be a problem with Qt Creator linking the library. I also tried the Qt-Visual-Studio-Add-in, but there, the same error occurs.
Here are my minimal examples with the library I want to include.
In the Visual Studio example, I added the library path, the include path, and the name of the library to the project properties. It works.
I hope you can help me with my problem.
EDIT:
I want to use the library to get some data from a S7-300 SPS device.
The following code is the minimal example from Qt Creator.
#include <QCoreApplication>
#include <QDebug>
#include <nodave.h>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
daveInterface *di;
daveSetDebug(daveDebugConnect); // Function of libnodave Library
qDebug() << "Hello World";
return a.exec();
}
This is the whole code from the Visual Studio minimal example.
#include "stdafx.h"
#include <nodave.h>
int _tmain(int argc, _TCHAR* argv[])
{
daveInterface *di;
daveSetDebug(daveDebugConnect);
printf("Hello World\n");
return 0;
}
The code is very small, so I don't think that there is an error inside.
That's why I think it must be a problem with the Qt linker or something like that.
EDIT:
My .pro file.
QT += core
QT -= gui
TARGET = qtminimal
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
win32: LIBS += -L$$PWD/../libnodave-0.8.5/win/ -llibnodave
INCLUDEPATH += $$PWD/../libnodave-0.8.5
DEPENDPATH += $$PWD/../libnodave-0.8.5
The problem was that the Qt project is 64bit and the library I want to include is only 32bit.
So I downloaded the 32bit version of Qt and now it works.
I found the mistake, when I tried to build only the minimal example with libnodave, without any 64bit Qt libraries.
By creating a new Qt project in VS2013, with this workaround and adding the libnodave library afterwards I could change whether it should be a 64bit or 32bit build. By choosing the 32bit build, the Qt library creates errors but not the libnodave lib. When I choose 64bit build, only libnodave creates the errors.
I hope it is useful for someone else.

undefined reference to `_imp__CryptUnprotectData#28' with Crypt32.Lib && wincrypt.h included

I have a problem with my one of my projects.
I use QtCreator with MinGW and Qt 5.4.0
When I try to compile, this simple line gets me some errors :
CryptUnprotectData(data.password, NULL, NULL, NULL, NULL, (DWORD) 0, data.uncryptedPassword);
( with DATA_BLOB* data.password and DATA_BLOB* data.uncryptedPassword )
Gets me :
undefined reference to `_imp__CryptUnprotectData#28'
As said on the title, I included the Crypt32.Lib file in my .pro :
QT += core gui
QT += sql
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = ChromePass
LIBS += -L$$PWD/ -lCrypt32
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
chromehandler.cpp \
passdata.cpp
HEADERS += mainwindow.h \
chromehandler.h \
passdata.h
FORMS += mainwindow.ui
And as instructed in the MSDN api, included wincrypt.h :
#include <windows.h>
#include <wincrypt.h>
#include <cstdlib>
#include <fstream>
The error being still there, I checked wincrypt.h to make sure CryptUnprotectData is defined, and it is :
WINIMPM WINBOOL WINAPI CryptUnprotectData(DATA_BLOB *pDataIn,LPWSTR *ppszDataDescr,DATA_BLOB *pOptionalEntropy,PVOID pvReserved,CRYPTPROTECT_PROMPTSTRUCT *pPromptStruct,DWORD dwFlags,DATA_BLOB *pDataOut);
I've been trying for the whole day ... does anyone have a clue ?
Thank you very much !
The clue is that crypt32 library is not built with mingw this is why you are getting linking errors.
Bad news is that there is no simple way to resolve that. You can read about some ways to resolve here:
MingW missing some functions from the Win32 Crypto API
Discussion on Qt forum about this question can be found here:
https://forum.qt.io/topic/25527/cannot-find-how-to-link-to-crypt32-dll