Access violation on adding QWidget to QTabWidget in Qt5.4
-
I recently upgraded to Qt5.4 and after adding to a QTabWidget this problem occurred:
First-chance exception at 0x000007FEDEE6A30A (Qt5Guid.dll) in MyApp.exe: 0xC0000005: Access violation reading location 0x0000000000000008
On continuing, application runs fine.
Fortunately I also found a quick fix relatively fast by trying to set some application attribute that just sounded right:Qt::AA_ImmediateWidgetCreation
Problem is that in the documentation it is indicated that this attribute is obsolete and is no longer supported.
I wonder if there is anything I am missing.@
void MainWindow::addEditorTab()
{
// CustomTabWidget inherits QWidget
CustomTabWidget* tab = new CustomTabWidget();
// tabs is a QTabWidget*
tabs->addTab( tab, tab->icon(), tab->title() ); // <-- access violation
}int main( int argc, char *argv[] )
{
...
QApplication app(argc, argv);
app.setAttribute( Qt::AA_DontCreateNativeWidgetSiblings ); //< fixes another bug
app.setAttribute( Qt::AA_ImmediateWidgetCreation); // < This fixes access violation
...
}
@In the callstack there are calls to qwindowsd.dll. This bug does not occur on Mac Osx.
Here the last part of the callstack:@Qt5Guid.dll!000007fedee6a30a()
Qt5Guid.dll!000007fedee5fff3()
Qt5Guid.dll!000007fedee6a22a()
Qt5Guid.dll!000007fedef06853()
Qt5Guid.dll!000007fedee92ba3()
Qt5Guid.dll!000007fedee9368e()
qwindowsd.dll!QWindowsWindow::handleGeometryChange() Line 1397 C++
qwindowsd.dll!QWindowsWindow::handleMoved() Line 1355 C++
qwindowsd.dll!QWindowsContext::windowsProc(HWND__ * hwnd, unsigned int message, QtWindows::WindowsEventType et, unsigned __int64 wParam, __int64 lParam, int64 * result) Line 986 C++
qwindowsd.dll!qWindowsWndProc(HWND * hwnd, unsigned int message, unsigned __int64 wParam, int64 lParam) Line 1236 C++
[External Code]
qwindowsd.dll!qWindowsWndProc(HWND * hwnd, unsigned int message, unsigned __int64 wParam, int64 lParam) Line 1245 C++
[External Code]
qwindowsd.dll!WindowCreationData::initialize(HWND * hwnd, bool frameChange, double opacityLevel) Line 669 C++
qwindowsd.dll!QWindowsWindow::setWindowFlags_sys(QFlags<enum Qt::WindowType> wt, unsigned int flags) Line 1549 C++
qwindowsd.dll!QWindowsWindow::setParent_sys(const QPlatformWindow * parent) Line 1259 C++@ -
Hi and welcome to devnet,
What is the tabs variable ?
Did you initialiaze it ?
-
Hi,
thanks for the reply and welcome.
As I stated in the comment above tabs is a QTabWidget*.
It is a member of Ui_MainWindow, generated from the UI-File.
MainWindow inherits QMainWindow and Ui::MainWindow.
setupUi( this ) is called in the constructor of MainWindow, where tabs is initialized.
addEditorTab() is called after the user double-clicks an item in a TreeWidget, long after MainWindow-initialization.Also note that this bug does not occur on Osx or Qt5.3.
-
I haven't seen this problem on Qt 5.4.0 on Windows. My application uses QTabWidget with a number of custom widgets. I just double checked to be sure.
The devil is in the details. In my case I am using a virtual machine (Xp x86) guest on OS X, compiler is MinGW, release build only. I compiled Qt from source.
Maybe you are mixing DLL files? Have you tried this with just a basic QWidget* added to QTabWidget? Do you get the same error with the release build (not Qt5Guid,qwindowsd)?
-
Hey,
I found the cause!
In the initialisation process inside the constructor of CustomTabWidget windowHandle()->winId() is called, which makes the QWidget native.
Maybe there is a problem with adding widgets as tabs that are already native?
Anyway I moved initialization to an init-function after tab is inserted, which fixes the problem for me.
Thank you all for the help! -
[quote author="SergejK" date="1423485248"]Hi,
thanks for the reply and welcome.
As I stated in the comment above tabs is a QTabWidget*.
It is a member of Ui_MainWindow, generated from the UI-File.
[/quote]Can you show me where ? After several re-reads I can't find it.
Anyway, so it only happens on Windows since 5.4, do I get you right ?
-
[quote author="SGaist" date="1423520133"][quote author="SergejK" date="1423485248"]Hi,
thanks for the reply and welcome.
As I stated in the comment above tabs is a QTabWidget*.
It is a member of Ui_MainWindow, generated from the UI-File.
[/quote]Can you show me where ? After several re-reads I can't find it.
[/quote]
line 5 in the first code section, its a comment.
[quote author="SGaist" date="1423520133"]
Anyway, so it only happens on Windows since 5.4, do I get you right ?
[/quote]
Yes and it seems to be caused by making the widget native before inserting as tab.
If you can reproduce it, maybe it is a bug in Qt.
Otherwise I am ok with the quick fix by adding the tab first, then making it native. -
[quote author="SergejK" date="1423560584"][quote author="SGaist" date="1423520133"][quote author="SergejK" date="1423485248"]Hi,
thanks for the reply and welcome.
As I stated in the comment above tabs is a QTabWidget*.
It is a member of Ui_MainWindow, generated from the UI-File.
[/quote]Can you show me where ? After several re-reads I can't find it.
[/quote]
line 5 in the first code section, its a comment.
[/quote]Ok, but neither it nor the code mention any UI file
Can you create a minimal compilable example that reproduces this behavior ?
-
Oh, sorry for the misunderstanding. I only meant the first part is mentioned in the comments.
Ok, I can reproduce the error with the following lines of code:
@
int main( int argc, char *argv[] )
{
QApplication app(argc, argv);QMainWindow* mainWindow= new QMainWindow(); QWidget *centralwidget = new QWidget(mainWindow); QHBoxLayout* horizontalLayout = new QHBoxLayout(centralwidget); QTabWidget * tabs = new QTabWidget(centralwidget); horizontalLayout->addWidget(tabs); QWidget* customTab = new QWidget(); customTab->windowHandle()->winId(); tabs->addTab(customTab, "name");
}@
-
Then you should check the "bug report system":http://bugreports.qt.io to see if it's something known