2011-04-10 46 views
2

我想添加3個項目到狀態欄。不應該每個人都在自己的標籤?Qt創建者C++,將很多標籤添加到狀態欄

這可能嗎?當我試圖添加第二個標籤時,它給了我一個錯誤。

文件mainwindow.h

QLabel *m_statusLabel; 
QLabel *m_pointLabel; 

文件mainwindow.cpp

statusBar()->addWidget(m_statusLabel); 
statusBar()->addWidget(m_pointLabel); 

它有一個標籤完美的作品,但是當我添加第二個,然後我得到以下。

Starting C:\Users\Jansu\Desktop\cpp-praktikum05-alus\Joonistamine-build-  desktop\src\bin\Joonistamine.exe... 
ASSERT: "d" in file ..\..\include/QtCore/../../src/corelib/tools/qscopedpointer.h, line 112 
Invalid parameter passed to C runtime function. 
Invalid parameter passed to C runtime function. 
C:\Users\Jansu\Desktop\cpp-praktikum05-alus\Joonistamine-build- desktop\src\bin\Joonistamine.exe exited with code -1073741819 
+0

這可能不是直接將狀態欄添加到小部件中導致的。你如何創建'QLabel'? – Mat 2011-04-10 15:04:07

+0

爲什麼要添加3個不同的小部件,而不是隻包含一切?也許[QStatusBar](http://doc.qt.nokia.com/latest/qstatusbar.html)僅支持一個小部件,但您也可以嘗試使用'addPermanentWidget'。 – ierax 2011-04-10 15:31:14

回答

4

我發現了這個問題。我忘了創建QLabels,所以我添加了這個:

m_statusLabel = new QLabel(this); 
m_pointLabel = new QLabel(this); 
相關問題