Using Visual Leak Detector with a QApplication - c++

I am trying to locate the memory leaks in my Qt application. I already have used Visual Leak Detector for some other projects, but VLD writes the output to the console window.
My problem now is that when using a QApplication, no console window, and therefore no output from VLD, is shown. I am using Visual Studio 2015 with the Qt VS Tools plugin.
Is there a way to force the application to show the console window? Or maybe a way to write the output generated by VLD to a file?
How I start up my application:
#include "mainwindow.h"
#include <vld.h>
#include <QApplication>
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}

As ssbssa pointed out as a comment, the problem could be solved by setting ReportTo and ReportFile in vld.ini found in the installation folder of VLD:
change ReportFile = to ReportFile = memory_leak_report.txt or something like that.
change ReportTo = debugger to ReportTo = file or ReportTo = both.
Now the output produced by VLD will be written to the specified file.

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.

QML C++ application crash outside Qt Creator

I am using Qt 5.1.1 with Visual Studio 2012 compiler. I have a Quick 2 application with a c++ backend. When i'm running application in Qt Creator everything looks good.
But when i'm trying to launch application outside from Qt Creator it crashes.
I have all Qt*.dll 's in my folder, also have D3DCompiler_46.dll.
I tried to access some filed in my QML file from C++ part, and I see that after crash in Visual Studio debugger that the crash look like null pointer exception.
QObject *openButton = instanceRoot->findChild<QObject*>("openFileButton");
openButton->setProperty("enabled",QVariant(enabled));
I have all my resources declared in qrc file, and it also included in my .pro file as
RESOURCES += res.qrc
By this article that menas, that all my qml files should be emdeded in my exe files. But I think it shouldn't.
How can I find and fix this problem?
UPD:
Here is my main function:
int main(int argc, char *argv[]) {
QGuiApplication a(argc, argv);
Q_INIT_RESOURCE(res);
QQuickView view;
Decrypter dec;
view.rootContext()->setContextProperty("Decrypter", &dec);
QObject::connect(view.engine(), SIGNAL(quit()), &a, SLOT(quit()));
view.setSource(QUrl("qrc:/PlayerGUI.qml"));
view.show();
QQuickItem *rootObject = view.rootObject();
Player *player = new Player(rootObject);
return a.exec();
}
UPD2: Two persons from comments were confused by one string of the code:
view.engine()->addImportPath("../QtAV/qml/");
So, I deleted it, and still have a crash(

Qt 5.0 [ui_mainwindow.h] Error -1073741515

I have a problem with Qt 5.0 as when I execute any simple code I have this error from linker.
-1: error: [ui_mainwindow.h] Error -1073741515
I'd like to know how to solve it.
This is the causing code snippit:
#include "mainwindow.h"
#include <QtGui/QApplication>
#include <QLabel>
int main(int argc, char *argv[]) {
QApplication prog(argc, argv);
QLabel *label = new QLabel("GameTime!");
label->show();
return prog.exec();
}
Your QLabel *label and show() code need to go in mainWindow.cpp
Your main.cpp should look like:
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
And your mainwindow.cpp (something like this)
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QLabel *label = new QLabel("GameTime!");
label->show();
}
I didn't test this exact mainwindow code, but it should be pretty close. I usually use the user interface builder that QT Creator comes with to access UI elements.
You did not enclose what development environment you are using, but assuming it uses MS linker cl.exe, it is highly assumably that the environment variables aren't set correctly.
This error is caused, if cl.exe is started on command line or from within a build script and can't find its needed mspdb80.dll in the path.
To avoid this, just make sure to set the environment properly. For MS VS2010 for example you would have to call
C:\RANDOM\PATH\>"%VS100COMNTOOLS%vsvars32.bat"
%VS100COMNTOOLS% is usually set by VS2010 installer on setup. If you are using a different version, that will be %VSx0COMNTOOLS% with x could be 5, 6,... according to your version of Visual Studio.
Output should be something like this:
Setting environment for using Microsoft Visual Studio 2010 x86 tools.

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