QApplication compiles with gcc 4.7 but crashes - c++

from here http://nuwen.net/mingw.html I've downloaded gcc 4.7 and I've set this up in qt. Everything compiles fine in qt, unfortunately when I run my app (from qt) it crashes.
Any thougts?
Edit (this is this application, OS Win7, Qt 4.8):
#include <QApplication>
#include <QDialog>
int main(int c, char** v)
{
QApplication app(c,v);
QDialog* d = new QDialog();
d->show();
return app.exec();
}

If you update the compiler, you should probably recompile Qt.
Different version of gcc can work together, but they might be themselves compiled with incompatible options.

Related

how to add qtvirtualkeyboard to a qt widget project

I have a Qt Widget project that I created using QtCreator and Qt version 5.15.2 to which I'm trying to add the QtVirtualKeyboard as matchbox-keyboard I've already tried using stays under the application when it's in fullscreen mode.
However I'm having trouble getting it to work as it's not appearing at all at the moment. This is how I've tried adding it
Main.cpp
#include "mainwindow.h"
#include <QApplication>
#include <QtWidgets>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
MainWindow w;
//w.showFullScreen();
w.show();
return a.exec();
}
I've tried adding QT += qtvirtualkeyboard or QT += virtualkeyboard in the .pro file but it just gives me an error saying "unknown module"
How can I add the virtual keyboard to the project?
You will need to make sure that the QtVirtualKeyboard library is selected during the installation process.
Also, I would recommend you that you start using cmake for Qt applications as Qt has officially dropped qmake since the release of Qt 6.
It is not to say that you cannot use it, but you will get better support and results by using an actively developed build system rather than an abandoned.

Qt program compiling with MSVC crash on app.exec()

I needed to include OpenCV into my program, so after long time, I gave up to set it up on mingw (which was fully functional for my program) and installed MSVC17 compiler and debugger. But when I run my application with MSVC, program crash with 0x0000005 code, access violation on 0xfffffff.
It always crash on app.exec() in main.cpp
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
MyClass myClass;
myClass.getView()->setMinimumWidth(900);
myClass.getView()->setMinimumHeight(600);
QQuickWindow *quickWindow = qobject_cast<QQuickWindow *>(myClass.getView());
quickWindow->setFlags(Qt::FramelessWindowHint);
//Connecting signal from QML to exit application
QObject::connect(myClass.getView()->engine(), SIGNAL(quit()), &app, SLOT(quit()));
quickWindow->show();
return app.exec(); //Here it crash
}
As I said, it fully worked with mingw (32 bit).
Can MSVC2017 x64 somehow crash when building app, that was previously used by mingw x32? Do anyone know how to fix it?
Thank you very much!
//EDIT:
Somehow, it works for release, but not for debug mode.
//EDIT:
It crashes only when app is showing visible QML object
This sounds like a 32 vs. 64-bit issue.
Try updating the dependencies on your item and see if that resolves it, you should be able to re-build the raw source to x64 if you specify that CPU build, and update any dependencies that are x86.
Or, run the app in 32-bit mode.

C++ compile problems with Qt for Visual Studio 2017

I have installed Qt Creator with the msvc2017_64 binary. I also installed the Qt add-in for VS2017. I can create a QtGuiApplication without any problems, but when i try to compile it, many errors appear. I listed them here, on pastebin, because I cannot add this many characters to Stackoverflow. I'm sorry for that.
Do I need any essential packages for this? I installed C++ for VS2017 ofc. I also included the QtPath in the Qt VS Tools menu.
I did not edit the files since project creation and compiling fails due to errors.
EDIT: This problem is solved here. But not only the Errors form Pastebin exist, also the one following in the QtGuiApplication.h
QtGuiApplication.h: (Errors marked as comments)
#pragma once
#include <QtWidgets/QMainWindow>
#include "ui_QtGuiApplication1.h" //This could not be found
class QtGuiApplication1 : public QMainWindow
{
Q_OBJECT
public:
QtGuiApplication1(QWidget *parent = Q_NULLPTR);
private:
Ui::QtGuiApplication1Class ui; //Ui namespace does not exist
};
QtApplication.cpp:
#include "stdafx.h"
#include "QtGuiApplication1.h"
QtGuiApplication1::QtGuiApplication1(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
}
main.cpp:
#include "stdafx.h"
#include "QtGuiApplication1.h"
#include <QtWidgets/QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QtGuiApplication1 w;
w.show();
return a.exec();
}
I solved this problem myself!
The Qt add-in creates the Project with the Windowns 8.1 SDK, you need to retarget it to the Win 10 SDK to get the compile Errors from the QtGuiApplication.h away. Even if the 8.1 SDK is installed. Seems like a bug.
The solution was quite simple to me, just unload and then reload the solution from Solution Explorer!
This will clear all c++ compiler errors! Don't know why ...

"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.

Qt4.8.1 undhandled exception at QMdiArea::addSubwindow

I compiled Qt 4.8.1 with these instructions:
http://www.holoborodko.com/pavel/2011/02/01/how-to-compile-qt-4-7-with-visual-studio-2010/
for my system (Visual Studio 2010, x64). The compilation worked and everything seemed Ok.
While compiling there is a lot of output, but it's very fast and therefore I can't read it so i suppose that shouldn't be a problem.
After I compiled succesfully my current project I got an unhandled runtime exception. After a while I discovered that it comes from the QMdiArea::addSubwindow function, which seems to throw the exception (I'm not able to catch it with overriden notify function though). So I searched for an example project to see if it's my code or something else. I found this example here:
http://www.codeprogress.com/cpp/libraries/qt/qMdiAreaAddSubWindow.php
And it works fine in 32bit mode as well as debug mode of x64, but again at the
QMdiArea::addSubwindow function there is an unhandled exception. Has anyone an idea what's wrong or had the same problem?
Currently I'm recompiling Qt to get the debug information again (i cleaned it beforehand).
But maybe someone had the same problem and a solution for me.
//Update:
The code is here (the exact same as in the link)
#include <QApplication>
#include <QMainWindow>
#include <QMdiArea>
#include <QMdiSubWindow>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QMainWindow window;
window.setFixedSize(800,600);
window.setWindowTitle(QString::fromUtf8("My QMdiWindow"));
QMdiArea* area = new QMdiArea();
area->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
//Create QMdiSubWindow
QMdiSubWindow* subWindow = new QMdiSubWindow();
subWindow->setFixedSize(200,100);
//Add subWindow to Main QMdiWindow here
area->addSubWindow(subWindow);
window.setCentralWidget(area);
window.show();
return app.exec();
}
//Update2:
I opened another discussion here.
Ok, I found the problem. It is a bug in the MSVC++ compiler. Installing the service pack and recompiling Qt again helps.