QApplication constructor segfault - c++

Earlier in the day, every thing worked nice as hell, suddenly it all broke.
#include <QtGui/QApplication>
int main(int argc, char** argv) {
QApplication app {argc, argv};
}
Compile with g++ main.cpp -lQtCore -lQtGui -I/usr/include/qt4, gives me a segfault, and I have no clue why.
I have made some investigation on the matter, and it seems that something may be wrong with either argc or argv, but earlier in the day this didn't happen at all.

Upgrading to Qt5 from Qt4 solved the problem.

Related

Project crash with lots of things on .pro, non referenced though

I have a Qt5 project based on qmake.
main.cpp is the following:
#include <QApplication>
#include <QWidget>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget w;
w.show();
return a.exec();
}
The project seems to build fine. However when I run it, it will crash. That's strange, right?
What could explain that is the bunch of files I added to the project .pro file.
Anyway, if that files are not referenced in the main.cpp, would that cause any trouble? I would not expect.
Context: I'm trying to build a small part of a bigger project and so I added all kinds of things in this project until it finally build.
I already deleted .pro.user and files created during build and tried to rebuild everything again.
And even the following will also crash
int main()
{
return 0;
}

Undefined reference to function in VlcQt (after installation)

I recently installed VlcQt libary for ubuntu 16.04, but when I try to use it, all i get is undefined reference to 'some_function()'.
Currently I am trying to expose video player to QML.
Main.cpp
#include <QGuiApplication>
#include <VLCQtCore/Common.h>
#include <VLCQtQml/QmlVideoPlayer.h>
#include "Controller.h"
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
VlcCommon::setPluginPath(app.applicationDirPath() + "plugins");
VlcQmlVideoPlayer::registerPlugin();
Controller controller;
QQuickWindow *quickWindow = qobject_cast<QQuickWindow *>(controller.view());
quickWindow->show();
return app.exec();
}
When I am trying to include libaries, Qt intellisense is detecting that this libary exists.
What am I doing wrong?
Thank you for your help!
//Edit:
I installed it via their repository:
add-apt-repository ppa:ntadej/tano
apt-get install libvlc-qt-core2 libvlc-qt-widgets2 libvlc-qt-dbg libvlc-qt-dev
//Edit:
This is how I add libs in .pro file, already tried INCLUDEPATH too
LIBS += -lvlccore -lvlc

QApplication stuck in constructor

I have following code compiled with Visual Studio 2013, x64 target and linked with QT 5.4. It compiles fine and it generates the executable.
int main(int argc, char** argv)
{
QApplication app(argc, argv);
QMainWindow mainWindow;
mainWindow.show();
return app.exec();
}
If I try to run it from the IDE it gets stuck on the line: QApplication app(argc, argv);, but if I run the executable directly works as expected, it creates a small windows and the process gets closed after the windows is closed. I have same behavior in both debug and release configurations.
Is anything wrong with the code? What may cause this weird problem?
EDIT: It gets stuck is something like an infinite loop inside. Unfortunately the call stack doesn't help me much about that because it looks like this if I hit "break all":
Qt5Core.dll!0000000066ae3291() Unknown
Qt5Core.dll!0000000066aa941f() Unknown
Qt5Core.dll!0000000066ad0da7() Unknown
Qt5Core.dll!0000000066b302b6() Unknown
Qt5Core.dll!0000000066b2e3a1() Unknown
Qt5Gui.dll!000007fee4fcde9f() Unknown
Qt5Widgets.dll!000000006441e1dc() Unknown
MyAwesomeApp.exe!main(int argc, char * * argv) Line 10 C++
EDIT1:
After changing the configuration to Win32, it works as expected when started from IDE.

"Using OS scope before setting MAKEFILE_GENERATOR" in Qt

I have downloaded and installed Qt and I'm learning how to use it.
So, I created a new project myfristqt (empty project). I then added a main.cpp file with this code:
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
return app.exec();
}
First thing I noticed #include <QApplication> line is hightlighted with a red line as if QApplication was an unknown identifier. So, I compiled it to see what happens and here's the error I got:
(internal):1: error : Using OS scope before setting MAKEFILE_GENERATOR
Any idea why this is happening ? I'm using Windows XP
MAKEFILE_GENERATOR is a qmake variable.
This variable contains the name of the Makefile generator to use when generating a Makefile. The value of this variable is typically handled internally by qmake and rarely needs to be modified.
It define in QTDIR/mkspecs/PLATFORM/qmake.conf. Where PLATFORM is maybe cygwin-g++, win32-msvc200x on your Windows XP.

Missing File application.h in gtkmm-3.0 on Ubuntu 11.10

I'm currently trying to compile some code examples from
http://developer.gnome.org/gtkmm-tutorial/unstable/sec-treeview-examples.html.en
but from what I can see Ubuntu 11.10 gtkmm-3.0 is missing the file
/usr/include/gtkmm-3.0/gtkmm/application.h
and I can't find it anywhere else:
apt-file search "gtkmm/application.h"
returns nothing.
Even more strange, Application is not referenced anywhere under /usr/include/gtkmm-3.0/gtkmm.
Here's the main function
#include "../examplewindow.hpp"
#include <gtkmm/application.h>
int main(int argc, char *argv[])
{
Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv, "org.gtkmm.example");
ExampleWindow window;
return app->run(window);
}
Have I missed something? Has the API changed recently?
After reading the good answers:
For now, with gtkmm 3.2, I use
#include "../examplewindow.hpp"
int main(int argc, char *argv[])
{
Gtk::Main kit(argc, argv);
ExampleWindow window;
Gtk::Main::run(window);
}
instead. What do I gain by using the 3.4 Application Interface instead?
According to the Gtk::Application documentation, it only exists on gtkmm 3.4+.
You can check the installed version of the package with:
pkg-config --modversion gtkmm-3.0
There was some issues wrapping GtkApplication for gtkmm 3.0 and 3.2. It's now in the 3.3.x development sources, but was recently considered "not ready". I assume it will be in good shape when 3.4 is released.