Emacs embedded in a Qt Application - qt

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.

Related

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?

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

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.

qcleanlooksstyle belongs to which QT += in Qt

I am searching "QCleanlooksStyle" belongs to which "QT +=". please help, ive centos 6.4 and Qt 5.3.
#include <QApplication>
#include <QCleanlooksStyle>
#include <QtWidgets>
#include "buttonbox.h"
int main( int argc, char **argv )
{
QApplication app( argc, argv );
app.setStyle( new QCleanlooksStyle );
ButtonBoxDialog dlg;
dlg.show();
return app.exec();
}
According to the docs:
QMotifStyle, QPlastiqueStyle, QCleanlooksStyle, and QCDEStyle are
replaced with a new fusion style. If your application depends on any
of these removed styles, you can either use the qtstyleplugins project
to get these styles or update your application to use the new fusion
style. For more details about this change, see
https://blog.qt.io/blog/2012/10/30/cleaning-up-styles-in-qt5-and-adding-fusion/.
So you must clone the project, compile it and install it:
git clone git://code.qt.io/qt/qtstyleplugins.git
cd qtstyleplugins/
qmake
make
sudo make install
Then you must set the style using the following (you should not modify the .pro):
app.setStyle("cleanlooks");

A new Qt widget application will not compile

I am relatively new to Qt and was going through many tutorials. Everything was fine. All scripts compiled and ran.
Then, at some point, I am getting the error for even a new Qt widget application created with Qt Creator 4.3.1:
C:\ \Documents\111\main.cpp:-1: In function 'int qMain(int, char**)':
C:\ \Documents\111\main.cpp:6: error: variable 'QApplication a' has initializer but incomplete type
QApplication a(argc, argv);
^
C:\ \Documents\111\main.cpp:11: warning: control reaches end of non-void function [-Wreturn-type]
}
^
I am not sure what happened, yet seems like some setups were messed up.
QApplication is included, and not missing in the script.
111.pro
# Project created by QtCreator 2018-02-23T01:36:28
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = 111
TEMPLATE = app
DEFINES += QT_DEPRECATED_WARNINGS
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
FORMS += \
mainwindow.ui
main.cpp
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
mainview.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
It seems to me that this issue appeared after trying to run qt5.6_src.zip examples from https://en.ids-imaging.com/open-source.html.
Without completed code, I guess you need to add #include <QApplication> to main.cpp
The error message told you what is missing.
According to Qt's docs, the constructor's signature is QApplication(int &argc, char **argv).
Therefore, if you inherit from QApplication then the subclass's constructor must pass argc by reference. From your description, it appears that the constructor of your subclass is actually passing argc by value (i.e., int qMain(int, char**) ). That will cause some problems.
The issue is fixed by deleting the Qt folder and QtCreator folder in the <drive>:\Users\<username>\AppData\Roaming\QtProject and <drive>:\Users\<username>\AppData\Roaming\Qt. It stored incorrect settings, which I somehow setup by running open source scripts. For more information visit Where does QtCreator save its settings?.

Boost in Qt: Installation and Symbol(s) not found for architectures x86_64

I am back to Qt and C++ programming after a year break. I am trying to install boost library into Qt on Mac (10.9.4) and I am completely confused. This is what I did:
I installed boost using homebrew.
I see that hpp files are installed here:
/usr/local/Cellar/boost/1.55.0_2/include/boost
and libraries here:
/usr/local/Cellar/boost/1.55.0_2/lib
Now I start a new Qt console project.
the project file:
QT += core
QT -= gui
TARGET = testQt
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += /usr/local/Cellar/boost/1.55.0_2
And the main file:
#include <QCoreApplication>
#include <QtCore>
#include <iostream>
#include <QDebug>
#include <boost/regex.hpp>
using namespace std;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
std::string line;
boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );
while (std::cin)
{
std::getline(std::cin, line);
boost::smatch matches;
if (boost::regex_match(line, matches, pat))
std::cout << matches[2] << std::endl;
}
return a.exec();
}
Not compiling. Issues:
Symbol(s) not found for architectures x86_64
linker command failed with exist code 1
Since I am absolutely noob with boost, did I do it right? If yes, why is it not compiling?
Thanks a lot!
You need to link with boost too!
LIBS += -L/usr/local/Cellar/boost/1.55.0_2/lib -lboost

Resources