I am working with Qt 5.2. I am using QNetworkAccessManager to make some posts to a web (without encryption). Now I have to verify a signature of message (That message has nothing to do with the post and QNetworkAccessManager, they are completly separated).
Both parts of code work fine separately, but when they come together the application crashes. If I add the OpenSSL to the application and I call a QNetworkAccessManager::post then it fails. The program pointer is in OPENSSL_sk_pop_free and it crashes after a QNetworkAccessManager::post call.
The code:
//#define OPENSSL
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <openssl/bio.h>
#if defined(OPENSSL)
#define USE_SHA1
bool validateLicense()
{
BIO* bio = BIO_new(BIO_s_mem());
BIO_free(bio);
return true;
}
#endif
int main() {
QNetworkAccessManager* manager = new QNetworkAccessManager();
QNetworkRequest request;
request.setUrl(QUrl("http:\\192.168.0.1"));
request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/json"));
QString com("{\"hello world\"}");
QByteArray data(com.toLocal8Bit());
qDebug() << Q_FUNC_INFO << "data to POST" << com;
manager->post(request, data);
#if defined(OPENSSL)
validateLicense();
#endif
}
The .pro file:
QT += core network
QT -= gui
CONFIG += c++11
TARGET = console
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
#
# libcrypto
#
LIBS += $$[OPENSSL_INSTALL_ROOT]/libcrypto.a
If I uncomment the #define OPENSSL the application crashes in line manager->post(request, data);.
How can I disable the OpenSSL in QNetworkAccessManager to avoid the application crash?
Related
When building several 3rd party libraries from source I get undefined symbols build errors or dll import errors.
Im trying to work out why certain functions don't link/can't be linked.
I am using qt creator 7.0.0 qt.6.2.4 online installer linked to LLVM 14.0.0 (13.0.0 has a bug with /MANIFESTDEPENDENCY)
I have followed the below link to build libxml(build with multithreadeddll or MD runtime)
https://forum.unified-automation.com/viewtopic.php?t=26
as well as followed a similar link to build libxslt.
I link to them in the .pro
INCLUDEPATH += ../../../Thirdparty/msvclibxml/include
INCLUDEPATH += ../../../Thirdparty/msvclibxml/include/libxml2
win32:DEPENDPATH += -L../../../Thirdparty/msvclibxml/lib -llibxml2
win32:LIBS += -L../../../Thirdparty/msvclibxml/lib -llibxml2
I have run into similar issues with building BMX when linking to self contained expat library in the code.
I don't experience any issue with my self built libraries, the AWS c++ sdk, FFmpeg so my general method isn't wrong.
Any help would be greatly appreciated.
Upon request here's the use case of lib xml that fails
in the header
//extern "C"
{
#include <libxml/tree.h>
#include <libxml/xmlmemory.h>
#include <libxml/debugXML.h>
#include <libxml/HTMLtree.h>
#include <libxml/xmlIO.h>
#include <libxml/xinclude.h>
#include <libxml/catalog.h>
#include <libxml/parser.h>
#include <libxml/HTMLparser.h>
#include <libxslt/xslt.h>
#include <libxslt/xsltInternals.h>
#include <libxslt/transform.h>
#include <libxslt/xsltutils.h>
}
the called function.
int pdfWriter::generatePDFObject(QString stylesheetFileName, QString xmlFilePath, QString &pdfFileName, QTextDocument &document, QString &formattedString)
{
QFile fileCheck(xmlFilePath);
if (!fileCheck.open(QIODevice::ReadOnly))
{
qDebug() << "Xml file does not exist";
return 2;
}
fileCheck.close();
QFileInfo fileCheckInfo(xmlFilePath);
if (fileCheckInfo.suffix().compare("xml", Qt::CaseInsensitive) != 0)
{
qDebug() << "File does not have xml extension";
return 1;
}
//Put this in eFFData
QString styleSheetFileName;
QString styleSheetCustomerImage;
QString path = "C:/Users/User/hardcodedpathexample";
styleSheetFileName = path;
styleSheetFileName.append("/");
styleSheetFileName.append(stylesheetFileName);
styleSheetCustomerImage = path;
styleSheetCustomerImage.append("/");
styleSheetCustomerImage.append("hardecodedimagesfilenameexample");
// Code to create pdf file
pdfFileName = xmlFilePath;
pdfFileName.remove(".xml");
pdfFileName.append(".pdf");
xmlDocPtr doc, res;
xmlOutputBufferPtr buf = xmlAllocOutputBuffer(NULL);
doc = xmlParseFile(xmlFilePath.toUtf8());
const char *params[1];
params[0] = nullptr;
xsltStylesheetPtr cur = NULL;
xmlSubstituteEntitiesDefault(1);
xmlLoadExtDtdDefaultValue = 1;
cur = xsltParseStylesheetFile((const xmlChar *)styleSheetFileName.toLocal8Bit().data());
res = xsltApplyStylesheet(cur, doc, params);
xsltSaveResultTo(buf, res, cur);
xsltFreeStylesheet(cur);
xmlFreeDoc(res);
xmlFreeDoc(doc);
xsltCleanupGlobals();
xmlCleanupParser();
formattedString = QString::fromUtf8((char*)(xmlOutputBufferGetContent(buf)));
xmlOutputBufferClose(buf);
QPixmap pixmap;
pixmap = QPixmap(":/logo/e-logo.png");
document.addResource(QTextDocument::ImageResource, QUrl("image file name example"), pixmap.scaled(350, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation));
QPixmap customerPixmap(styleSheetCustomerImage);
document.addResource(QTextDocument::ImageResource, QUrl("image file name example"), customerPixmap.scaled(350, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation));
return 0;
}
multiple function fail - mainly xmlAllocOutputBuffer(Null) undefined symbol
I've been looking around on the web on how to create an authentication page when my Qt desktop app opens. I already built the app; that is pretty small and only composed of a MainWindow called from main.cpp.
Now I'd like to add an authentication page when the user opens the app. I created a Google API (following the instruction from this link: http://blog.qt.io/blog/2017/01/25/connecting-qt-application-google-services-using-oauth-2-0/); but it is really incomplete. And looking on the web, I wasn't able to find a single link that gives a working example where:
- The user runs the app and gets asked for his username and password;
- And if it doesn't exist yet, he can create one.
All I've found is incomplete piece of code like the link I shared above; or tutorial that shows how to create a login page with hard-coded passwords and usernames (this is not what I want, I want people to be able to add themselves dynamically based of the Google API).
So please, if someone has a little piece of code where the user gets asked for their username and password, with the code managing the request to the API, that would be great!
EDIT: Adding my code
I'm adding the code of my class GoogleGateway (inspired from what I found here: How to set redirect_uri using QOAuth2AuthorizationCodeFlow and QOAuthHttpServerReplyHandler)
GoogleGateway.h:
#ifndef GOOGLEGATEWAY_H
#define GOOGLEGATEWAY_H
#include <QObject>
class GoogleGateway : public QObject
{
Q_OBJECT
public:
GoogleGateway();
};
#endif // GOOGLEGATEWAY_H
GoogleGateway.cpp:
#include "googlegateway.h"
#include <QApplication>
#include <QObject>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QString>
#include <QFile>
#include <QUrl>
#include <QOAuth2AuthorizationCodeFlow>
#include <QOAuthHttpServerReplyHandler>
#include <QDesktopServices>
GoogleGateway::GoogleGateway() :
QObject(){
auto google = new QOAuth2AuthorizationCodeFlow;
google->setScope("email");
this->connect(google, &QOAuth2AuthorizationCodeFlow::authorizeWithBrowser, &QDesktopServices::openUrl);
QString val;
QFile file;
file.setFileName("/.../auth.json");
file.open(QIODevice::ReadOnly | QIODevice::Text);
val = file.readAll();
file.close();
QJsonDocument document = QJsonDocument::fromJson(val.toUtf8());
QJsonObject object = document.object();
const auto settingsObject = object["web"].toObject();
const QUrl authUri(settingsObject["auth_uri"].toString());
const auto clientId = settingsObject["client_id"].toString();
const QUrl tokenUri(settingsObject["token_uri"].toString());
const auto clientSecret(settingsObject["client_secret"].toString());
const auto redirectUris = settingsObject["redirect_uris"].toArray();
const QUrl redirectUri(redirectUris[0].toString());
const auto port = static_cast<quint16>(redirectUri.port());
google->setAuthorizationUrl(authUri);
google->setClientIdentifier(clientId);
google->setAccessTokenUrl(tokenUri);
google->setClientIdentifierSharedKey(clientSecret);
auto replyHandler = new QOAuthHttpServerReplyHandler(port, this);
google->setReplyHandler(replyHandler);
google->grant();
}
Now, what do I need to do in my MainWindow.cpp to prompt a login page that will use the class GoogleGateway? Does the class GoogleGateway look good as it is? Or do I need to modify something?
Also, I created an instance of the class GoogleGateway in my MainWindow constructor. And When I run the code, it opens a web tab in my Chrome but throws the Error 400 saying "Error: redirect_uri_mismatch". What does that mean?
Thanks for your help.
So, the article from Qt blog is almost complete. You just need to connect granted signal and make needed requests after that.
Note about /cb path in redirect_uri in Qt blog is not valid anymore(article came about a year ago).
NOTE: The path “/cb” is mandatory in the current
QOAuthHttpServerReplyHandler implementation.
So if you see access error from google after running your code, just copy-paste redirect_uri from there into GoogleConsole Authorized redirect URIs of your configured client. http://localhost:8080/ <- don't forget slash at the end
P.S.: Don't forget to dowload json file with credentials from console again.
Also if you want to call any Google APIs after authorization, you need to enable them in GoogleConsole for your project. To test the code just enable Google+ API
That's it. Here is the complete and working code. (Tested on Linux and Qt 5.10, Don't have Windows at the moment, can't test it there)
googlegateway.h
#ifndef GOOGLEGATEWAY_H
#define GOOGLEGATEWAY_H
#include <QObject>
#include <QOAuth2AuthorizationCodeFlow>
#include <QNetworkReply>
class GoogleGateway : public QObject
{
Q_OBJECT
public:
explicit GoogleGateway(QObject *parent = nullptr);
private:
QOAuth2AuthorizationCodeFlow * google;
};
#endif // GOOGLEGATEWAY_H
googlegateway.cpp
#include "googlegateway.h"
#include <QObject>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QString>
#include <QFile>
#include <QDir>
#include <QUrl>
#include <QOAuthHttpServerReplyHandler>
#include <QDesktopServices>
GoogleGateway::GoogleGateway(QObject *parent) : QObject(parent)
{
this->google = new QOAuth2AuthorizationCodeFlow(this);
this->google->setScope("email");
connect(this->google, &QOAuth2AuthorizationCodeFlow::authorizeWithBrowser, &QDesktopServices::openUrl);
QByteArray val;
QFile file;
file.setFileName(QDir::toNativeSeparators("/full/path/client_secret_XXXXXXX.apps.googleusercontent.com.json"));
if(file.open(QIODevice::ReadOnly | QIODevice::Text))
{
val = file.readAll();
file.close();
}
QJsonDocument document = QJsonDocument::fromJson(val);
QJsonObject object = document.object();
const auto settingsObject = object["web"].toObject();
const QUrl authUri(settingsObject["auth_uri"].toString());
const auto clientId = settingsObject["client_id"].toString();
const QUrl tokenUri(settingsObject["token_uri"].toString());
const auto clientSecret(settingsObject["client_secret"].toString());
const auto redirectUris = settingsObject["redirect_uris"].toArray();
const QUrl redirectUri(redirectUris[0].toString());
const auto port = static_cast<quint16>(redirectUri.port());
this->google->setAuthorizationUrl(authUri);
this->google->setClientIdentifier(clientId);
this->google->setAccessTokenUrl(tokenUri);
this->google->setClientIdentifierSharedKey(clientSecret);
auto replyHandler = new QOAuthHttpServerReplyHandler(port, this);
this->google->setReplyHandler(replyHandler);
this->google->grant();
connect(this->google, &QOAuth2AuthorizationCodeFlow::granted, [=](){
qDebug() << __FUNCTION__ << __LINE__ << "Access Granted!";
auto reply = this->google->get(QUrl("https://www.googleapis.com/plus/v1/people/me"));
connect(reply, &QNetworkReply::finished, [reply](){
qDebug() << "REQUEST FINISHED. Error? " << (reply->error() != QNetworkReply::NoError);
qDebug() << reply->readAll();
});
});
}
Please remember to set Redirect URI in google console to http://127.0.0.1:port_no/ instead of http://localhost:port_no/ for all localhost.
Remember to put the trailing '/' in the Redirect URI.
Rest of the code
this->google = new QOAuth2AuthorizationCodeFlow(this);
this->google->setScope("email");
connect(this->google, &QOAuth2AuthorizationCodeFlow::authorizeWithBrowser, &QDesktopServices::openUrl);
this->google->setAuthorizationUrl(QUrl("https://accounts.google.com/o/oauth2/auth"));
this->google->setClientIdentifier(MY_CLIENT_ID);
this->google->setAccessTokenUrl(QUrl("https://oauth2.googleapis.com/token"));
this->google->setClientIdentifierSharedKey(MYTOKEN);
// In my case, I have hardcoded 8080 to test
auto replyHandler = new QOAuthHttpServerReplyHandler(8080, this);
this->google->setReplyHandler(replyHandler);
this->google->grant();
qDebug() << "Access";
connect(this->google, &QOAuth2AuthorizationCodeFlow::granted, [=](){
qDebug() << __FUNCTION__ << __LINE__ << "Access Granted!";
auto reply = this->google->get(QUrl("https://www.googleapis.com/plus/v1/people/me"));
connect(reply, &QNetworkReply::finished, [reply](){
qDebug() << "REQUEST FINISHED. Error? " << (reply->error() != QNetworkReply::NoError);
qDebug() << reply->readAll();
});
});
I am trying to make an application in Qt to configure a bluetooth module RN42 http://ww1.microchip.com/downloads/en/DeviceDoc/rn-42-ds-v2.32r.pdf . In order to configure the module some command have to be sent via serial port, but here is where the extrange things start happening. I conecto it to the computer via xbee xplorer and I can configure it without any problems using my application, but when I try to retreive the current configuration no response is got, I can see that the device enters in configuration mode because the led blinks faster, but I cannot get any feedback from the device via serial port.
So I decided to start debugging with arduino due, if I connect it via programming port I can comunicate wihout problems, but if I connect it with the USB native port I do not get any information from the device. But if I open the port with the arduino serial monitor, the comunication starts, then close the arduino serial monitor, open my application and I am comunicating without problems.
I have also tried to comunicate with docklight (a serial monitor application) and again I have no problem comunicating, but if after comunicating with docklight I try to comunicate with my application no response will be got, unlike arduino serial monitor.
Eventhough I debugged with an oscilloscope and I can see that the information is sent once the port is closed.
I have tried many different things and I do not know what I am doing wrong. I tink it is related with the configuration of the port, but not sure, could it be a bug with the QtSerialport?
Here are my programs. I am using Qt creator 5.9.1 in windows with MinGW53_32
QT
.pro
#-------------------------------------------------
#
# Project created by QtCreator 2017-07-25T08:39:59
#
#-------------------------------------------------
QT += core gui
QT += serialport
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = BT_Config_Tool
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
bluetooth_config.cpp
HEADERS += \
bluetooth_config.h
FORMS += \
bluetooth_config.ui
bluetooth_config.h
#ifndef BLUETOOTH_CONFIG_H
#define BLUETOOTH_CONFIG_H
#include <QMainWindow>
#include <QTimer>
#include <QSerialPort>
#include <QtSerialPort>
#include <QtSerialPort/QtSerialPort>
#include <stdio.h>
#include <math.h>
#include <QSerialPortInfo>
#define BUFFMAX 1000
namespace Ui {
class bluetooth_config;
}
class bluetooth_config : public QMainWindow
{
Q_OBJECT
public slots:
void ReadDevice(void);
void FlashDevice(void);
void UpdateCombobox(void);
void ReadSerial(void);
public:
explicit bluetooth_config(QWidget *parent = 0);
~bluetooth_config();
private slots:
void on_pushButton_clicked();
void on_pushButton_2_clicked();
void on_pushButton_3_clicked();
private:
Ui::bluetooth_config *ui;
QSerialPort *_port;
QTimer *_timerRead;
QTimer *_timerFlash;
QTimer *_timerUpdateCombobox;
QSerialPortInfo *_serialPortInfo;
int _cFlash = 0;
int _cRead = 0;
char _buffer[BUFFMAX];
//QByteArray _buffer;
int c;
};
#endif // BLUETOOTH_CONFIG_H
bluetooth_config.cpp
#include "bluetooth_config.h"
#include "ui_bluetooth_config.h"
const char *nameFlash;
const char *passFlash;
const char *nameRead;
char trama[BUFFMAX];
int item = 0;
bluetooth_config::bluetooth_config(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::bluetooth_config)
{
ui->setupUi(this);
ui->label_4->setVisible(false);
ui->label_5->setVisible(false);
_timerRead = new QTimer(this);
connect(_timerRead,SIGNAL(timeout()),this, SLOT(ReadDevice()));
_timerFlash = new QTimer(this);
connect(_timerFlash,SIGNAL(timeout()),this, SLOT(FlashDevice()));
_timerUpdateCombobox = new QTimer(this);
connect(_timerUpdateCombobox,SIGNAL(timeout()),this, SLOT(UpdateCombobox()));
_timerUpdateCombobox->start(2000);
_port = new QSerialPort();
_port->setBaudRate(QSerialPort::Baud115200);
_port->setDataBits(QSerialPort::Data8);
_port->setParity(QSerialPort::NoParity);
_port->setStopBits(QSerialPort::OneStop);
_port->setFlowControl(QSerialPort::NoFlowControl);
connect(_port,SIGNAL(readyRead()),this,SLOT(ReadSerial()));
//ui->tabWidget->setTabEnabled(0, false);
}
bluetooth_config::~bluetooth_config()
{
delete ui;
}
void bluetooth_config::ReadDevice()
{
_cRead ++;
if (_cRead == 1){
_port->write("$$$");
ui->lcdNumber_2->display(_cRead);
_timerRead->stop();
}
else if (_cRead == 2){
_port->write("---\r\n");
_port->waitForBytesWritten();
ui->lcdNumber_2->display(_cRead);
_timerRead->stop();
}
else if (_cRead == 3){
ui->label_5->setVisible(true);
ui->lcdNumber_2->display(_cRead);
_timerRead->stop();
_cRead = 0;
}
}
void bluetooth_config::FlashDevice()
{
_cFlash ++;
if (_cFlash == 1){
_port->write("$$$");
}
else if (_cFlash == 2){
nameFlash = ui->lineEdit->displayText().toUtf8().constData();
strcpy(trama, "SN,");
strcat(trama,nameFlash);
strcat(trama,"\n\r");
_port->write(trama);
}
else if (_cFlash == 3){
passFlash = ui->lineEdit_2->displayText().toUtf8().constData();
strcpy(trama, "SP,");
strcat(trama,passFlash);
strcat(trama,"\n\r");
_port->write(trama);
}
else if (_cFlash == 4){
_port->write("---\n\r");
}
else if (_cFlash == 5){
_cFlash = 0;
_timerFlash->stop();
ui->label_4->setVisible(true);
}
}
void bluetooth_config::UpdateCombobox()
{
item = ui->comboBox->currentIndex();
ui->comboBox->clear();
foreach (const QSerialPortInfo &serialPortInfo, QSerialPortInfo::availablePorts())
{
ui->comboBox->addItem(serialPortInfo.portName());
}
if (item <= (ui->comboBox->count() - 1) && item >= 0){
ui->comboBox->setCurrentIndex(item);
}
else {
ui->comboBox->setCurrentIndex(ui->comboBox->count() - 1);
}
}
void bluetooth_config::ReadSerial()
{
int ojete = _port->bytesAvailable();
ui->lcdNumber->display(ojete);
//_port->read(_buffer,BUFFMAX);
QByteArray a = _port->readAll();
//ui->plainTextEdit->appendPlainText(_buffer);
ui->plainTextEdit->appendPlainText(a);
if (_cRead == 1 || _cRead == 2){
_timerRead->start(50);
}
}
void bluetooth_config::on_pushButton_clicked()
{
ui->label_5->setVisible(false);
_timerRead->start(50);
_port->flush();
}
void bluetooth_config::on_pushButton_2_clicked()
{
ui->label_4->setVisible(false);
_timerFlash->start(50);
_port->flush();
}
void bluetooth_config::on_pushButton_3_clicked()
{
if (!_port->isOpen()){
_port->setPortName(ui->comboBox->currentText());
if (_port->open(QIODevice::ReadWrite)){
ui->label_3->setText("Puerto abierto");
ui->pushButton_3->setText("Cerrar");
ui->pushButton->setEnabled(true);
ui->pushButton_2->setEnabled(true);
}
else {
ui->label_3->setText("Ha ocurrido un error al abrir el puerto");
}
}
else {
_port->close();
ui->label_3->setText("Puerto cerrado");
ui->pushButton_3->setText("Abrir");
ui->pushButton->setEnabled(false);
ui->pushButton_2->setEnabled(false);
}
}
main.cpp
#include "bluetooth_config.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
bluetooth_config w;
w.show();
return a.exec();
}
Thank you very much.
Alejandro
I have a problem with connection to a web service with ssl protocol. I was trying to connect with specyfied WebService using open libraries QtSoap. Since now I have been searching any solution of error which I have mentioned in the topic, but not found any for linux-mint system. Only one I have seen, which people confirmed were for Windows here 1 and here 2. I have certificate for this webService which contains a key.
My pice of code:
#include "qtsoap.h"
...
int main(int argc, char **argv)
{
...
QtSoapMessage message;
QSsl::SslProtocol protocol = QSsl::SslV2;
message.addHeaderItem(new QtSoapSimpleType(QtSoapQName("tagName"),"tagValue"));
...
message.setMethod("method", "WSAddress");
message.addMethodArgument("attr", "", value);
...
QtSoapHttpTransport http;
http.setHost("ipaddress", true, port);
http.setAction("http://tempuri.org/IDataService/DARTGetReservationData");
http.submitRequest(message, "path", protocol, "certificatePath");
}
I have made some changes in a library if You have already noticed in submitRequest, adding specyfied SslProtocol and certificatePath. Here is a sorce:
void QtSoapHttpTransport::submitRequest(QNetworkRequest &networkReq, QtSoapMessage &request, const QString &path, QSsl::SslProtocol ssl, QString certificatePath)
{
networkReq.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("text/xml;charset=utf-8"));
networkReq.setRawHeader("SOAPAction", soapAction.toLatin1());
url.setPath(path);
networkReq.setUrl(url);
QSslConfiguration sslConf = networkReq.sslConfiguration();
soapResponse.clear();
if(certificatePath != NULL)
{
QFile sslCertificateFile(certificatePath);
if (sslCertificateFile.open(QIODevice::ReadOnly))
{
QSslCertificate certif(&sslCertificateFile);
if (certif.isNull())
{
qDebug() << "Failed to load certificate";
}
sslConf.setLocalCertificate(certif);
sslConf.setPrivateKey(certif.publicKey());
qDebug() << "certif version=" << certif.version() << ", serial=" << certif.serialNumber()
<< ", issuer=" << certif.issuerInfo(QSslCertificate::Organization)
<< " and subject=" << certif.subjectInfo(QSslCertificate::CommonName);
QSslKey key(certif.publicKey());
qDebug() << "key isNull ? " << key.isNull();
sslConf.setPrivateKey(key);
sslCertificateFile.close();
}
else
qDebug() << "Cannot open certificate";
}
if(ssl != NULL)
sslConf.setProtocol(ssl);
networkReq.setSslConfiguration(sslConf);
networkRep = networkMgr.post(networkReq, request.toXmlString().toUtf8().constData());
}
One more thing related to this modified libraries. I added some headers to:
#include <QSslCertificate>
#include <QSsl>
#include <QSslConfiguration>
#include <QSslKey>
#include <QFile>
I guess that there is missing something in my *.pro file, but I do not know what it could be. So I added it below
QT += core network xml
QT -= gui
TARGET = SSLConnectionTest
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp \
qtsoap.cpp
HEADERS += \
qtsoap.h
Another thing that could be wrong is there is missing some other libraries which I don't know. I hope someone have found solution of this problem?
Sorry for my poor english.
I saw this question already on this forum but I do not know why the proposed answer does not work in my case. So I try to ask for other slution.
I just got my Qt creator running under Linux.
I do not understand why my:
cout << "This does not appear";
Does not print in console while qdebug does
qDebug() << "This appears";
This is what is contained in my .pro file:
QT += core gui
TARGET = aaa
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
IeplcModule.cpp
HEADERS += mainwindow.h \
IeplcModule.h
FORMS += mainwindow.ui
#enable console
CONFIG += console
Any idea?
Try with:
cout << "asdf" << endl;
Possibly Qt sets up iostream in order to flush only at new line.
When debugging with CDB (Windows debugger) and running application not in the dedicated terminal window, but within QtCreator output panel, there is an issue with std::cout/std::cerr.
qDebug works because it has a trick for this case.
So, the only solution in this case is enable the "run in terminal" option.
For more infor please follow the link above to the Qt bug tracker.
Is it possible that STDOUT is redirecting? qDebug prints to STDERR by default.
Did you #include <iostream>? I did not see any includes in the code.
I assume that qdebug and cout are very similar.
Make sure you have console config enabled in your .pro file. I.e. :
CONFIG += console
You can run this program from CMD and it will print some messages to the console:
/* Create a .pro file with this content:
QT += core gui widgets
SOURCES += main.cpp
TARGET = app
-------------------------------
Build and run commands for CMD:
> qmake -makefile
> mingw32-make
> "release/app"
*/
#ifdef _WIN32
#include <windows.h>
#endif
#include <QtCore/QFile>
#include <QtCore/QString>
#include <QtCore/QIODevice>
#include <QtWidgets/QApplication>
#include <QtWidgets/QWidget>
#include <iostream>
class Widget : public QWidget
{
public:
Widget()
{
setWindowTitle("My Title");
QString path("assets/text.txt");
std::cout << std::endl;
std::cout << "hello1" << std::endl;
std::cout << path.toStdString() << std::endl;
std::cout << "hello2" << std::endl;
}
};
int main(int argc, char *argv[])
{
#ifdef _WIN32
if (AttachConsole(ATTACH_PARENT_PROCESS))
{
freopen("CONOUT$", "w", stdout);
freopen("CONOUT$", "w", stderr);
}
#endif
QApplication app(argc, argv);
Widget w;
w.show();
return app.exec();
}