QScriptEngine::evaluate("print(test)") not functional anymore - qt

I need to migrate qt/4.8.6 code to qt/5.9 . I am struggling with using print statement within QScriptEngine evaluate statement. In simplified form implementation looks like:
#include <iostream>
#include <QApplication>
#include <QtScript>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QScriptEngine engine;
std::cout << "Hello, world!\n";
engine.evaluate("print('test\n\n')");
}
.pro file
CONFIG += qt
CONFIG += console
SOURCES += main.cc
QT += widgets
QT += script
sources.files = main.cpp qscript.pro
INSTALLS += sources
->output to console:
Hello, world!
in qt/4.8.6 it prints out evaluated print statement to console "Hello, world! test", whereas in qt/5.9 it prints only "Hello, world!"
Any idea, why using print command is not working? Note, I need to implement printing to stdout by using js scripting+ evaluate.

Related

how to build simple qt application using yocto?

I have yocto dev environment setup, in which I can bitbake and run a simple c++ application in the target. Now I want to try with simple Qt application. When I execute bitbake-layers show-layers it shows meta-qt5 in the list...
meta-qt5
/home/prc1cob/repo/out/salt/kawa/../../..//os/external/meta-qt5 7
meta-oe
/home/prc1cob/repo/out/salt/kawa/../../../build/yocto/meta-openembedded/meta-oe
6
With this, I assume qt5 is already present in my yocto build.
How to write .bb file to build a simple HelloWorld qt application as below...
#include <QCoreApplication>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
qDebug() << "Hello World";
return a.exec();
}
Thankyou!!
Yocto provides a great class qmake5 to compile QT projects based on QMake.
In order to use it create a .pro file for the project:
qtexample.pro
QT += core
SOURCES += qtexample.cpp
qtexample.cpp
#include <QCoreApplication>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
qDebug() << "Hello World";
return a.exec();
}
Now, in your layer, you can add a simple recipe that compiles that project.
For example: meta-custom/recipes-project/qtexample
In qtexample folder create files folder and copy qtexample.pro and qtexample.cpp in it.
In qtexample folder directly create qtexample_0.1.bb recipe:
SUMMARY = "QT Example Recipe"
LICENSE = "CLOSED"
SRC_URI = "file://qtexample.pro \
file://qtexample.cpp"
DEPENDS += "qtbase"
RDEPENDS_${PN} += "qtwayland"
S = "${WORKDIR}"
inherit qmake5
You can change the version ofcourse (0.1).
The layout should look like this:
meta-custom/
├── recipes-project/
├── qtexample_0.1.bb
└── files/
├── qtexample.pro
└── qtexample.cpp
Then, bitbake qtexample should work and create a qtexample binary that you can find in ${WORKDIR}

Why do QProcess (Qt 5.15.1) and GDB lead to missing symbols?

I am currently having some trouble debugging a program that starts processes via QProcess.
Simply executing the binary without dbg works just fine but when I try to debug the executable with gdb I am getting a SIGTRAP when the process has started.
After that the stack always shows '??' instead of function names.
When continuing I get a SIGILL.
I found out that the trap is not caused when no breakpoint is set.
In my project I also get following output:
Probes-based dynamic linker interface failed.
I am not sure whether this is related to loaded plugins or libraries.
The problem can be reproduced (except from the " Probes-based dynamic linker interface failed." output) with the following code:
#include <QCoreApplication>
#include <QProcess>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QProcess proc;
QString exe = "echo";
QStringList arguments;
arguments << "Test";
proc.start(exe, arguments);
if (!proc.waitForFinished()) {
qDebug() << "failed to start" << proc.exitCode() << proc.errorString();
}
qDebug() << "process finished";
qDebug() << proc.readAllStandardOutput();
return a.exec();
}
My OS is arch linux (up to date)
Qt5: qt5-base 5.15.1-1
GDB: gdb 9.2-1
clang++: clang 10.0.1-1
Does anybody have an idea what is causing the SIGTRAP when debugging with dbg?

Using DLL's in Qt: undefined reference

I want to use an SDK I got for using a scanner. I'm using Qt 5.3 with MingW32 (on Windows 7).
The very first test I wanted to build should just print the SDK version.
Here is my project file
QT += core
QT -= gui
TARGET = Kojak1
CONFIG += console
CONFIG -= app_bundle
KOJAKDIR = "C:/Program Files/Integrated Biometrics/IBScanUltimateSDK_x64"
TEMPLATE = app
INCLUDEPATH += $$KOJAKDIR/Include
SOURCES += main.cpp
LIBS +=-L$$KOJAKDIR/lib/ -lIBScanUltimate
and here is the source code
#include <QCoreApplication>
#include "stdio.h"
#include <windows.h>
#include "IBScanUltimateApi.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
IBSU_SdkVersion sdk_version;
IBSU_GetSDKVersion(&sdk_version);
printf("%s %s",sdk_version.File,sdk_version.Product);
return a.exec();
}
Unforturnately I get the message
D:\devt\QTProjects\Kojak1\main.cpp:10: error: undefined reference to `IBSU_GetSDKVersion#4'
when trying to compile the program.
My lib directory does contain IBScanUltimate.lib and IBScanUltimate.dll.

Emacs embedded in a Qt Application

I've tried to embed emacs in a Qt Application using QX11EmbedContainer, and works but with two important exception. First of all, here is the code:
#include <QX11EmbedWidget>
#include <QtGui>
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QX11EmbedContainer container;
container.show();
container.resize(500, 500);
QProcess* process = new QProcess(&container);
QString executable("emacsclient");
QStringList arguments;
arguments << "--parent-id" << QString::number(container.winId());
process->start(executable, arguments);
int status = app.exec();
process->close();
return status;
}
And the compilation and execution line (and the previous thrown of the emacs server):
$ emacs -q --daemon &
// filtered output
$ g++ test.cpp -lQtGui -lQtCore -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4
$ ./a.out
And finally, the result:
But, when or if I try to write something in the minibuffer, the size of the widget is collapsed, and the focus is also lost:
If I make click in the (now shorter) widget, I can continue working with emacs without problems, but I should resize the window in order to emacs is expanded other time as originally.
Where is the problem?
Try using a layout.
Here is the Qt5 documentation on layout management.

missing std::runtime_error in qt+mingw

I've tried to compile the following code using Qt(4.6.3) + MinGW:
#include <QtCore/QCoreApplication>
#include <exception>
int main(int argc, char *argv[])
{
throw std::runtime_error("");
QCoreApplication a(argc, argv);
return a.exec();
}
... and got this error:
..\untitled11\main.cpp:6: error: 'runtime_error' is not a member of 'std'
Project created from scratch(console application), the pro file:
QT += core
QT -= gui
TARGET = untitled11
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
Tried to compile this using Qt+MSVC2008 compiler - works fine.
This is a standard exception, have no idea why is missing.
<exception> defines only the base std::exceptionclass; if you want child classes like std::runtime_error, you must include the <stdexcept> header.

Resources