The following application crashes on mainWindow->show();
#include <QApplication>
#include <QFrame>
#include <QPixmap>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Q_INIT_RESOURCE(resources);
QPixmap pix;
pix.load(":/resources/images/app/icon_glow.png");
QFrame *mainWindow = new QFrame;
mainWindow->setWindowIcon(QIcon(pix));
mainWindow->show();
return a.exec();
}
With the mainWindow->setWindowIcon(QIcon(pix)); commented out, everything works. Otherwise, the backtrace (SEGFAULT, trying to dereference 0x8; seems like a missing nullptr check somewhere) is:
0 ?? /usr/local/Qt32/5.3/gcc/plugins/platforms/libqxcb.so 0xf4991138
1 ?? /usr/local/Qt32/5.3/gcc/plugins/platforms/libqxcb.so 0xf4982d4c
2 ?? /usr/local/Qt32/5.3/gcc/plugins/platforms/libqxcb.so 0xf498e7e3
3 ?? /usr/local/Qt32/5.3/gcc/plugins/platforms/libqxcb.so 0xf498f0f4
4 QWindowPrivate::applyCursor() /usr/local/Qt32/5.3/gcc/lib/libQt5Gui.so.5 0xf7517942
5 QWindowPrivate::setCursor(QCursor const*) /usr/local/Qt32/5.3/gcc/lib/libQt5Gui.so.5 0xf75179f7
6 QWindow::setCursor(QCursor const&) /usr/local/Qt32/5.3/gcc/lib/libQt5Gui.so.5 0xf7517b16
7 ?? /usr/local/Qt32/5.3/gcc/lib/libQt5Widgets.so.5 0xf7ad5d65
8 QWidgetPrivate::show_sys() /usr/local/Qt32/5.3/gcc/lib/libQt5Widgets.so.5 0xf7ad60b6
9 QWidgetPrivate::show_helper() /usr/local/Qt32/5.3/gcc/lib/libQt5Widgets.so.5 0xf7abab35
10 QWidget::setVisible(bool) /usr/local/Qt32/5.3/gcc/lib/libQt5Widgets.so.5 0xf7abb005
11 QWidget::show() /usr/local/Qt32/5.3/gcc/lib/libQt5Widgets.so.5 0xf7aad77e
12 main main.cpp 17 0x804a21f
I tried loading the resource as follows:
QLabel *mainLabel = new QLabel;
mainLabel->setPixmap(pix);
mainLabel->show();
That works without a problem. Any help is greatly appreciated. Ubuntu 14.04 x64, compiled 32 bit, Qt 5.3
UPDATE: I reinstalled ubuntu-desktop (i reverted the desktop from 32 bit to 64 bit) and now I get an error:
The X11 connection broke: Maximum allowed requested length exceeded (code 4)
XIO: fatal IO error 2 (No such file or directory) on X server ":0"
after 409 requests (409 known processed) with 0 events remaining.
I have also encountered this. The reason is the icon is too large. Resize to something smaller, 256x256 for example.
Related
I want to capture shortcut Cmd+Plus to do something (zoom something). But as I found this does not work on MacBooks because Cmd+Plus has to be pressed with holding Shift key. So instead of Cmd+Plus I got Cmd+Shift+=. What is interesting: on Windows and Linux everything works as expected (Ctrl instead of Cmd, of course).
A piece of code:
#include <QApplication>
#include <QDebug>
#include <QKeyEvent>
#include <QWidget>
class Widget : public QWidget
{
public:
void keyPressEvent(QKeyEvent *event) override {
qInfo() << event->key() << event->modifiers();
}
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
When I press Cmd+Plus (with holding Shift), this code outputs 61 QFlags<Qt::KeyboardModifier>(ShiftModifier|ControlModifier) on my MacBook. Note that 61 is decadic number of '='.
This code outputs 43 QFlags<Qt::KeyboardModifier>(ShiftModifier|ControlModifier) on Windows and Linux notebooks which also require pressing Shift. But here 43 is '+'. Which is correct.
Well, how to capture Cmd+Plus then? On all platforms (equiv. Ctrl instead of Cmd on Windows and Linux), on all possible national keyboard layouts?
I am a new guy to Qt although I have been writing in C for many years only about a year or so using c++. We are writing a camera app which has some C++ code for accessing frame buffers, video, etc. and a GUI that is written in QML. It is necessary to invoke gstreamer in a c++ class which needs to run in a separate thread and needs to be invoked from the QML code (because the QML code hangs waiting for threads to finish if it is invoked before starting the QML).
I found what looked like a great way to do it in the answer to someone else's question: How Start a Qthread from qml?. Unfortunately when I attempted to modify my code to run as shown in one of the answers I am getting a SIGABT signal. This happens when the code executes the following line:
view.engine()->rootContext()->setContextProperty("thread", &gstworker);
The main.cpp function looks like this:
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQuickView>
#include <QQmlContext>
#include <gst/gst.h>
#include "common.h"
#include "fbctl.h"
#include "gstcameraif.h"
#include "gstworker.h"
int main(int argc, char *argv[])
{
DBG_PRINT("main.cpp: register FbCtl type\n");
qmlRegisterType<FbCtl>("test.fbctl.qt", 1, 0, "FbCtl");
DBG_PRINT("main.cpp: register GstCameraIf type\n");
qmlRegisterType<GstCameraIf>("test.gstcameraif.qt", 1, 0, "GstCameraIf");
DBG_PRINT("main.cpp: register GstWorker type");
qmlRegisterType<GstWorker>("test.gstworker.qt", 1, 0, "GstWorker");
gst_init(&argc, &argv);
GstCameraIf gStreamer;
FbCtl fbSetup; // get a local instance of the frame buffer control object
fbSetup.setupOverlay(); // initialize the overlay setup
fbSetup.stopProcess(); // close opened descriptors, unmap frame buffers
qputenv("QT_QPA_EGLFS_FB", "dev/fb1"); // redirects QT to use fb1 (overlay) and gstreamer will go to fb0
GstWorker gstworker;
QQuickView view;
view.engine()->rootContext()->setContextProperty("thread", &gstworker);
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
gst_deinit();
return app.exec();
}
The function call list (stack) shows the following trace:
1 __GI_raise raise.c 54 0xb5ae1910
2 __GI_abort abort.c 89 0xb5ae2ca0
3 qt_message_fatal qlogging.cpp 1687 0xb5e0fff8
4 QMessageLogger::fatal qlogging.cpp 795 0xb5e0fff8
5 qt_pixmap_thread_test qpixmap.cpp 74 0xb670ce98
6 QPixmap::QPixmap qpixmap.cpp 109 0xb670ce98
7 QCursorData::QCursorData qcursor.cpp 624 0xb66a3360
8 QCursorData::initialize qcursor.cpp 655 0xb66a3360
9 QCursor::QCursor qcursor.cpp 470 0xb66a3360
10 QWindowPrivate::QWindowPrivate qwindow_p.h 107 0xb6bb3a78
11 QQuickWindowPrivate::QQuickWindowPrivate qquickwindow.cpp 501 0xb6bb3a78
12 QQuickViewPrivate::QQuickViewPrivate qquickview.cpp 77 0xb6c306e0
13 QQuickView::QQuickView qquickview.cpp 166 0xb6c30778
14 main main.cpp 38 0x131c8
My question is what do I need to fix to get rid of the sigabt signal.
thanks for any help you can give.
When I got the error again I noticed that it was actually happening when I declared the QQuickView object. I changed the main.cpp to use the QQmlApplicationEngine (instead of creating a quickview engine) to set the context and the error no longer occurs.
FYI: The SIGABT error was given in a message box and that is all it said.
I would like to give credit to #m7913d for the help in solving this issue.
I have a function in my pkcs#11 library that I want to open a wxwidgets window when called. The function will be called when the pkcs#11 C_Sign function is called by firefox. (My C_Sign function calls login_dialog)
Here is the code
#include <wx/wx.h>
#include "wx/wxprec.h"
#include <pthread.h>
class wxP11App2 : public wxApp
{
public:
virtual bool OnInit();
};
DECLARE_APP(wxP11App2)
// Use _NO_MAIN since we don't want main() to be created
IMPLEMENT_APP_NO_MAIN(wxP11App2);
bool wxP11App2::OnInit()
{
printf("OnInit\n");
wxFrame *frame = new wxFrame((wxFrame*) NULL, -1, _T("Hello wxWidgets World"));
frame->CreateStatusBar();
frame->SetStatusText(_T("Hello World"));
frame->Show(true);
SetTopWindow(frame);
printf("OnInit done\n");
return true;
}
void* start_wxapp_func(void* args)
{
printf("Thread func\n");
int argc = 0;
wxChar* argv = NULL;
wxApp* pApp = new wxP11App2();
wxApp::SetInstance(pApp);
wxEntry(argc, &argv);
return NULL;
}
int login_dialog()
{
int rv = 0;
pthread_t thread1;
pthread_create( &thread1, NULL, start_wxapp_func, NULL);
int count = 0;
while(1) {
printf("Sleep: %d\n", count++);
sleep(1);
}
return rv;
}
However, firefox crashes when wxEntry is being called. If I call C_Sign from a newly created c++ program (as opposed to when firefox calls the C_Sign function) it works. I get my wxwidgets window. I don't use any other GUI in that program. (There is neither any wxwidgets context nor gtk context).
It seems that it's gtk that crashes firefox so I thought it might have something to do that firefox already has a gtk instance running (and since wxwidgets uses gtk it might be a problem).
Do you have any suggestions on what I should try?
UPDATE:
Here is a stack trace from firefox built with debug info:
0 gdk_drawable_get_screen mozgtk.c 561 0x7f5ab2291b09
1 wx_gdk_window_get_screen gtk2-compat.h 391 0x7f5a859beca4
2 wxClientDisplayRect display.cpp 80 0x7f5a859bedb2
3 wxGetClientDisplayRect gdicmn.cpp 902 0x7f5a85ae5300
4 wxTopLevelWindowBase::GetDefaultSize toplvcmn.cpp 216 0x7f5a85b7f8fb
5 wxTopLevelWindowGTK::Create toplevel.cpp 571 0x7f5a859d3955
6 wxFrame::Create frame.cpp 56 0x7f5a85a3bb75
7 wxFrame::wxFrame frame.h 31 0x7f5a8679dd0c
8 wxP11App2::OnInit LoginDlg_linux.cpp 27 0x7f5a8679d825
9 wxAppConsoleBase::CallOnInit app.h 93 0x7f5a8679db95
10 wxEntry init.cpp 479 0x7f5a858b789f
11 start_wxapp_func LoginDlg_linux.cpp 47 0x7f5a8679da2a
12 start_thread 312 0x7f5ab1e60182
13 clone 111 0x7f5ab116947d
So in my code, it's the creation of a new wxFrame that crashes the program.
If the problem is really due to using 2 sets of mismatching GTK+ libraries, then the most straightforward solution is to build wxWidgets using exactly the same version of GTK+ and dependent libraries that was used for building your Firefox. In practice, the simplest way to do it would probably be to build it under the same system where Firefox was built.
This is definitely not ideal from the maintenance perspective, but unfortunately I just can't suggest any other solution. If your code is GPL you could try linking GTK+ statically, but it's usually not recommended for various reasons and if it's not GPL you can't do it anyhow.
I'm trying to make drag and drop inside a tree widget work to be able to move items around inside that widget. I've managed to make items draggable but when I release the mouse button the item disappears. To narrow it down I've tried the following example (taken from another post here on SO) which has the same issues as my tree widget in Qt 5.4 on Windows 7:
#include <QListWidget>
int main(int argc, char **argv)
{
QApplication a(argc, argv);
QListWidget lw;
for(int i = 1; i < 10; ++i)
lw.addItem(new QListWidgetItem(QString("Item %1").arg(i)));
lw.setDragEnabled(true); // ***
lw.viewport()->setAcceptDrops(true); // ***
lw.setDefaultDropAction(Qt::MoveAction); // ***
lw.setDropIndicatorShown(true); // ***
lw.setDragDropMode(QAbstractItemView::InternalMove);
lw.show();
a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
a.exec();
}
When I run this code and drag/drop some items it looks like this:
Why is the dragged item removed? Any ideas of what I'm missing?
I have changed one line in your code:
lw.setDefaultDropAction(Qt::TargetMoveAction);
and now it works fine (Qt 5.4.1 Windows 8, Visual Studio 2013).
It's a bug in Qt 5.4.1, your code work correctly on Qt 4.8.6
With Qt 5.10 or later, you have to call "setMovement(QListView::Free)"
myList->setDragDropMode(QAbstractItemView::InternalMove);
myList->setDefaultDropAction(Qt::TargetMoveAction);
#if QT_VERSION >= QT_VERSION_CHECK(5,10,0)
myList->setMovement(QListView::Free);
#endif
Just recently I've installed the Qt libraries on my computer, and as a complete novice I looked up the Qt 4.7 Getting Started guides online.
Just on the first page they provide the following code:
1 #include <QtGui>
2
3 int main(int argv, char **args)
4 {
5 QApplication app(argv, args);
6
7 QTextEdit textEdit;
8 QPushButton quitButton("Quit");
9
10 QObject::connect(&quitButton, SIGNAL(clicked()), qApp, SLOT(quit()));
11
12 QVBoxLayout layout;
13 layout.addWidget(&textEdit);
14 layout.addWidget(&quitButton);
15
16 QWidget window;
17 window.setLayout(&layout);
18
19 window.show();
20
21 return app.exec();
22 }
Simple stuff, I would suppose. Upon writing this code in Visual Studio Express 2010, building, and running, most everything works. However, when I try to close the window by means of the "Quit" button or the red-x in the top right of the displayed window (initiating "return app.exec()"), I receive the following:
A dialog box saying,
Unhandled exception at 0x77bc15de in ParticleTracker.exe: 0xC0000005: Access violation reading location 0xdf94b4b4.
And console output saying,
Critical error detected c0000374
Windows has triggered a breakpoint in ParticleTracker.exe.
This may be due to a corruption of the heap, which indicates a bug in ParticleTracker.exe or any of the DLLs it has loaded.
This may also be due to the user pressing F12 while ParticleTracker.exe has focus.
Having entered the debug-mode, I continued through the call stack while repeatedly receiving heap corruption errors.
First-chance exception at 0x77c6e6c3 in ParticleTracker.exe: 0xC0000374: A heap has been corrupted.
Unhandled exception at 0x77bc15de in ParticleTracker.exe: 0xC0000374: A heap has been corrupted.
All of the subsequent exceptions occurred at 0x77bc15de in the executable, with the memory address 0xC0000374 as a corrupted heap.
Honestly, I'm not precisely sure how I could even be getting this issue; I'm not well-versed in C++, but there appears to be nothing wrong with the code.
In the Call-Stack, the process is currently stuck at:
ParticleTracker.exe!main(int argv, char** args) Line 20 + 0x27 bytes
If I enter the disassembly the process is stuck at:
return app.exec();
00FE3831 mov esi,esp
00FE3833 call dword ptr [__imp_QApplication::exec (0FE93D0h)]
00FE3839 cmp esi,esp
00FE383B call #ILT+320(__RTC_CheckEsp) (0FE1145h)
00FE3840 mov dword ptr [ebp-150h],eax
00FE3846 mov byte ptr [ebp-4],5
00FE384A mov esi,esp
00FE384C lea ecx,[ebp-84h]
00FE3852 call dword ptr [__imp_QWidget::~QWidget (0FE9404h)]
00FE3858 cmp esi,esp
Any tips? Much appreciated. :)
Try this one
#include <QtGui>
int main(int argv, char **args)
{
QApplication app(argv, args);
QTextEdit *textEdit = new QTextEdit();
QPushButton *quitButton = new QPushButton("Quit");
QObject::connect(quitButton, SIGNAL(clicked()), qApp, SLOT(quit()));
QVBoxLayout *layout = new QVBoxLayout();
layout->addWidget(textEdit);
layout->addWidget(quitButton);
QWidget *window = new QWidget();
window->setLayout(layout);
window->show();
return app.exec();
}
It might be about ownership. When a widget is destroyed, it also takes care of its children, in your case, layouts and child widgets. QWidget destructior tries to destruct the objects, but they were allocated on the stack, and not dynamically.
Try to use dynamic allocation for QLayouts and widgets.