Not enough memory? - qt

I am dealing with NI DAQmx and they define unsigned long as uInt32. I declare uInt32 array [1048*1024] in the header file and it compiles, but when I try to run it, it seems to freeze, and when I stop it, it exits with an error:
The program has unexpectedly finished.
D:\Projects\build-BlackAndWhite12bit-Desktop_Qt_5_1_1_MinGW_32bit-Debug\debug\BlackAndWhite12bit.exe exited with code -1073741571
Well, it does not say that there is not enough memory, but since I allocate 4*1048*1024 = 4,292,608 bytes, and my version is Qt Creator 2.8.1 Based on Qt 5.1.1 (MSVC 2010, 32 bit) on Win7 x64, I expect it to not have enough memory.
I found a similar question Qt Creator - calloc fails with large memory, but the only solution that works for me, would be, probably, moving to 64bit. But how do I do that? I tried to download the application from this website with the Qt 5.2.1 for Windows 64-bit (VS 2012, 556 MB) link. But when I got it, it seems to be a 32bit version configured for 64bit. Is this the one I need? Do I need OpenGL?
Is there a way to allow more memory for my current Qt version?
Any other ways to go around my problem?
Here's the .h content:
#ifndef MAIN12BITSAMPLING_H
#define MAIN12BITSAMPLING_H
#include <QMainWindow>
#include "nivision.h"
#include "nivis.h"
#include "NIDAQmx.h"
namespace Ui {
class main12bitSampling;
}
class main12bitSampling : public QMainWindow
{
Q_OBJECT
public:
explicit main12bitSampling(QWidget *parent = 0);
~main12bitSampling();
...
uInt32 ddata[1073152];
...
signals:
private slots:
private:
Ui::main12bitSampling *ui;
};
#endif // MAIN12BITSAMPLING_H
Here's the main.c:
#include "main12bitsampling.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
main12bitSampling w;
w.show();
return a.exec();
}
And here's the main12bitsampling.cpp:
main12bitSampling::main12bitSampling(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::main12bitSampling)
{
ui->setupUi(this);
mainLoop();
}
main12bitSampling::~main12bitSampling()
{
delete ui;
}

-1073741571==0xc00000fd
and c00000fd is the error code for a stack overflow.
Keeping such large arrays statically where it can end up on the stack is problematic, allocate it on the heap and you will be much better off:
QVector<uInt32> ddata;
main12bitSampling::main12bitSampling(QWidget *parent = 0)
QMainWindow(parent), ddata(1024*1048)
{
//...
}

Related

user-defined literals and whitespace and c++11 issues

I'm compiling very simple code and as output I receive error:
`../untitled6/main.cpp:17:1: error: unable to find string literal operator 'operator"" __FILE__'
connect(&d_t, SIGNAL(timeout()), this, SLOT(doPlay()));`
The code is following:
#include <QObject>
#include <QTimer>
class Test : public QObject
{
Q_OBJECT
public:
explicit Test(QObject *parent = 0) : QObject(parent) {}
void Play()
{
connect(&d_t, SIGNAL(timeout()), this, SLOT(doPlay()));
}
public slots:
void doPlay() {}
private:
QTimer d_t;
};
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Test test;
test.Play();
return a.exec();
}
It is happened only if I include c++11 support in my project. Without this support the compilation is Okey. I have read about user-defined literals and whitespace for gcc ver. 4.7 when c++11 support is included. But my code doesn't include any FILE code.... I found that problem is related to SIGNAL and SLOT constructions. But I have no idea what is wrong here...
P.S. For compilation I use sh4-linux-g++ (GCC) 4.8.
I have found that this issue don't observed for release build configuration. It seems it is issue for debug build configuration...
This has been fixed in Qt 4.8.1:
https://bugreports.qt.io/browse/QTBUG-22847
You should upgrade.

Qt 5 with USB video grabber

My demo code is to choose a camera from the integrated camera of my laptop, and a USB video grabber (STK1160). My code is attached.
main.cpp:
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
mainwindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QCamera>
#include <QCameraInfo>
#include <QCameraImageCapture>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow {
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
QList <QCameraInfo> camList;
QCamera *camera;
private slots:
void onCameraChanged(int);
};
#endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent), ui(new Ui::MainWindow) {
ui->setupUi(this);
camera = NULL;
connect(ui->cameraComboBox,static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),this,
&MainWindow::onCameraChanged);
// find all available cameras and put them in the combo box
camList = QCameraInfo::availableCameras();
for(QList <QCameraInfo>::iterator it = camList.begin();it!=camList.end();++it) {
ui->cameraComboBox->addItem(it->description());
}
}
MainWindow::~MainWindow() {
delete ui;
}
void MainWindow::onCameraChanged(int idx) {
if(camera != NULL) {
camera->stop();
}
camera = new QCamera(camList.at(idx),this);
camera->setViewfinder(ui->viewfinder);
camera->setCaptureMode(QCamera::CaptureStillImage);
camera->start();
}
My problem is that when I choose the USB grabber from the combo box, I got the following error message:
libv4l2: error turning on stream: Message too long
CameraBin error: "Error starting streaming on device '/dev/video1'."
CameraBin error: "Could not negotiate format"
and the camera view is all black. Anyone has any idea? I have tested my video input on an AV screen, it works well.
I don't have a very concrete answer, but a more general one about camera & media APIs inside Qt5. In my experience some features only work on some platforms while other work on other platforms. For example I am currently struggling with having QVideoProbe work on Ubuntu even if it works fine on Android.
And development focus by Qt developers seems to be 80% on the mobile platforms recently. Also on Linux platforms the "backend" for video is gstreamer, which means that most errors originate there. My best tip is to upgrade to Qt 5.6 which relies on gstreamer1.0 instead of the ancient gstreamer0.1. Also make sure to install all the gstreamer plugins etc for your platform, as this may have a big impact on how well media works.
Also if you can reproduce the error directly in gstreamer, you might be able to find a fix for it there and this fix will then be available from Qt as well. For example if you are missing a codec or driver, using the gstreamer tools to add the support you need might solve the problem
I find the media APIs in Qt to be solid and I know that work is continuously being made to fill in the massing features in each platform's media back-end, so for each update of Qt more features should be added and bugs should be fixed.
I hope this helps, even if it does not address your question directly (which probably is because very few have the exact experience that you had).

Why is my mainwindow closing automatically when called from a differnet class?

I can't seem to figure out what went wrong so I'm here to ask you. I have made a simple class called BOBSNetworkSessionManager defined below. It is a simple class that inherits the QOBject so that I can use signals and slots but it does not have a dialog or any kind of window associated with it. It will eventually call a log in dialog and use the credentials to connect to a tcp server that I have created. This class serves as a layer to manage the connection state of the program because it will only run properly when connected to the server and when being used within 15 minutes without break due to p.c.i. compliance. If these conditions are not true this class will lock the window and force a new login. As of right now I just try to arbitrarily open the main window as though credentials had passed and i wasbconnected to the server. The problem is when I open the mainwindow it disapears right away. I cannot seem to figure out why it is diappearing. I have included all of my files.
BOBSDCNetworkSessionManager .h header file
#ifndef BOBSDCNETWORKSESSIONMANAGER_H
#define BOBSDCNETWORKSESSIONMANAGER_H
#include <QObject>
#include <QSettings>
class BOBSDCNetworkSessionManager : public QObject
{
Q_OBJECT
public:
explicit BOBSDCNetworkSessionManager(QObject *parent = 0);
protected:
void destroyed(QObject *);
signals:
public slots:
private:
void readSettings();
void writeSettings();
QSettings networkSettings;
};
#endif // BOBSDCNETWORKSESSIONMANAGER_H
BOBSDCNetworkSessionManager Implementation .cpp file
#include "bobsdcnetworksessionmanager.h"
#include "bobsmainwindow.h"
BOBSDCNetworkSessionManager::BOBSDCNetworkSessionManager(QObject *parent) :
QObject(parent)
{
BOBSMainWindow w;
w.show();
}
Main.cpp file
#include "bobsdcnetworksessionmanager.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
a.setApplicationName("Enterprise Management Suite");
a.setApplicationVersion("Beta Version: 0.0.0.01");
a.setOrganizationName("Enigma Web Consulting");
a.setOrganizationDomain("http://www.EnigmaWebCo.com");
BOBSDCNetworkSessionManager netMgr;
return a.exec();
}
The problem is here:
{
BOBSMainWindow w;
w.show();
}
w.show() is not a blocking call. So you're creating a window, showing it, and then it immediately is destructed when it goes out of scope. You should either declare w as a member variable or construct it on the heap:
BOBSMainWindow *w = new BOBSMainWindow(this);

Loading and unloading textures crashes the system

While debugging an application written in Qt using OpenGL ES 2.0 on a Linux embedded ARM platform, I noticed that when repeatedly loading and unloading textures, the embedded platform I'm working on started to behave strangely. I therefore wrote a simple test code to stress the OpenGL library:
main.cpp
#include <QApplication>
#include "mainwidget.h"
int main(int argc, char** argv)
{
QApplication a(argc, argv);
MainWidget widget;
widget.showFullScreen();
return a.exec();
}
and mainwidget.h:
#include <QElapsedTimer>
#include <QTimer>
#include "mainwidget.h"
MainWidget::MainWidget(QWidget *parent) :
QGLWidget(parent)
{
makeCurrent();
QTimer* t = new QTimer();
t->setSingleShot(false);
t->setInterval(10);
connect(t, SIGNAL(timeout()), this, SLOT(textureLoadingTest()));
t->start();
}
void MainWidget::textureLoadingTest()
{
QImage image(256, 512, QImage::Format_ARGB32);
image.fill(Qt::red);
QElapsedTimer timer;
timer.start();
GLuint code = bindTexture(image);
qDebug("Texture loaded in %lldms to code = %u.", timer.elapsed(), code);
deleteTexture(code);
}
This code seems to completely crash the system after 20/30 thousands textures.
Is this a bug in the test code or a system problem?

I just cannot get QTcpServer working (newConnection never called)

I know similar question to this have been asked, but I haven't found an answer that fixes my problem.
I'm adapting some existing Qt code to add server functionality to a program my company uses. To that end I added a QTcpServer object to the existing dialog, call listen() and connect a slot to the newConnection emitter, like:
.h
class QConsole : public QDialog
{
Q_OBJECT
public:
void init();
public slots:
void new_Connection();
private:
QTcpServer m_Server;
}
.cpp
void QConsole::init()
{
m_Server.listen(QHostAddress::Any, 12346);
QDialog::connect(&m_Server, SIGNAL(newConnection()), this, SLOT(new_Connection()));
}
Main is:
int main( int argc, char *argv[] )
{
QApplication app(argc, argv);
QConsole * _output_window = new QConsole(desktopRect);
_output_window->init();
_output_window->show();
return app.exec();
}
new_Connection() never gets called so I can't see the relevance, but here it is:
void QConsole::new_Connection()
{
}
This works fine in that my program starts listening on the port specified and if I telnet to it a connection of sorts it made, but new_Connection() is never ever ever called!
I've seen posts on this problem dating back to 2005 so it's obviously not a new thing, but what I haven't found is a satisfactory answer to the problem (or any answer actually). This has got everyone at work stumped, even the person that has written a Qt server program. I'm guessing that there is something fundamentally wrong with the existing framework, but I have no idea what it might be.
I have been tearing my hair out for a day and a half over this, and the closes I got to success was using waitForNewConnection() which would actually return me a socket, but when I connected to the readReady() emitter, that was never fired either. So what would prevent these signals never getting called?
Please spare my sanity and help me as much as you can.
Here is a complete working example, tested using MSVC++ 2010.
This listens for a connection on port 12346, replies with "HELLO WORLD" and logs the connection to a list on the dialog.
main.cpp
#include <QtGui>
#include "console.hpp"
int main(int argc, char** argv)
{
QApplication app(argc, argv);
Console con;
con.show();
return app.exec();
}
console.hpp
#include <QtCore>
#include <QtGui>
#include <QtNetwork>
class Console : public QDialog
{
Q_OBJECT
public:
Console();
public slots:
void connection();
private:
QTcpServer mServer;
QListWidget* mConnList;
};
console.cpp
#include "console.hpp"
Console::Console() :
QDialog(),
mServer(),
mConnList(new QListWidget())
{
if (!mServer.listen(QHostAddress::Any, 12346))
qDebug() << "Error during 'listen'" << mServer.errorString();
connect(&mServer, SIGNAL(newConnection()), this, SLOT(connection()));
QVBoxLayout* mainLayout = new QVBoxLayout();
mainLayout->addWidget(mConnList);
setLayout(mainLayout);
}
void Console::connection()
{
qDebug() << "CONNECTION";
QTcpSocket* skt = mServer.nextPendingConnection();
if (!skt)
return;
mConnList->addItem(QString("%1:%2").arg(skt->peerAddress().toString()).arg(skt->peerPort()));
skt->write("HELLO WORLD!\r\n");
skt->close();
}
test.pro
TEMPLATE=app
CONFIG+=console debug
QT=core gui network
HEADERS=console.hpp
SOURCES=main.cpp console.cpp
Another working example, again on Linux, although I have coded a program using QTcpServer to run on both Linux and Windows before without a problem. If this doesn't work, surely it must be either a Qt installation or OS configuration problem. Either that or a bug in the Qt version.
~/tcp_test$ qmake --version
QMake version 2.01a
Using Qt version 4.8.6 in /usr/lib/x86_64-linux-gnu
~/tcp_test$ for file in qconsole.{h,cpp} main.cpp tcp_test.pro ; do echo -e "$file:\n"; cat $file; echo; echo; done
qconsole.h:
#include <QDialog>
#include <QTcpServer>
class QConsole : public QDialog
{
Q_OBJECT
public:
QConsole();
public slots:
void connection();
private:
QTcpServer server;
};
qconsole.cpp:
#include "qconsole.h"
QConsole::QConsole()
{
server.listen(QHostAddress::Any, 12346);
QDialog::connect(&server, SIGNAL(newConnection()), this, SLOT(connection()));
}
void QConsole::connection()
{
qDebug("got connection");
}
main.cpp:
#include <QApplication>
#include "qconsole.h"
int main( int argc, char *argv[] )
{
QApplication app(argc, argv);
QConsole * window = new QConsole();
window->show();
return app.exec();
}
tcp_test.pro:
QT = core gui network
CONFIG += debug
TARGET = tcp_test
SOURCES = main.cpp qconsole.cpp
HEADERS = qconsole.h
~/tcp_test$ ./tcp_test &
[3] 9784
~/tcp_test$ nc localhost 12346
got connection
^C

Resources