February 8, 2011

xeroblast xeroblast
Lab Rat
91 posts

QListWidget bug

 

is this a bug? i created a QListWidget with more than 2 items and every first select of the 2nd and up item will cause the currentTextChanged(QString) signal to emit twice..

  1. void Window::Window() {
  2.  setupUI(this);
  3.  QListWidgetItem *a = new QListWidgetItem("hello");
  4.  QListWidgetItem *b = new QListWidgetItem("world");
  5.  QListWidgetItem *c = new QListWidgetItem("foo");
  6.  QListWidgetItem *d = new QListWidgetItem("bar");
  7.  listWidget->addItem(a);
  8.  listWidget->addItem(b);
  9.  listWidget->addItem(c);
  10.  listWidget->addItem(d);
  11.  connect(listWidget, SIGNAL(currentTextChanged(QString)), this, SLOT(selectItem(QString)));
  12. }
  13. void Window::selectItem(QString val) {
  14.  QMessageBox::information(this, "blah", val);
  15. }

if the QListWidget has no item selected yet and you select the ‘world’, ‘foo’ & ‘bar’ values, the messagebox appear twice unless you select the ‘hello’ value.
this is what i understand, on your first select/click of the item in the QListWidget (except the first item), it sends a signal that the first item is selected then the chosen item will send a signal that it is the changes made in the QListWidget.

5 replies

February 8, 2011

Volker Volker
Robot Herder
5428 posts

I cannot reproduce this behavior. I get the signal only once.

I’m on a Mac here. Could be some platform problem, but I doubt that.

February 8, 2011

Gerolf Gerolf
Area 51 Engineer
3210 posts

Hi,

I did not check now, but might that be something with the focus?
If the list widget has no focus, depending on the configuration of the designer, it might select one item on setFocus and then send the new selection….

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

February 8, 2011

Deleted Member # 4a2 Deleted Member # 4a2
Ant Farmer
1481 posts
Volker wrote:
I cannot reproduce this behavior. I get the signal only once. I’m on a Mac here. Could be some platform problem, but I doubt that.

just tried and can’t reproduce this on windows too.

February 9, 2011

xeroblast xeroblast
Lab Rat
91 posts

i tested it on a stand-alone and when the UI gets loaded, the messagebox appear with the value of the first item. so i think, the problem is on focus because when i put another widget and it is on first select on tab. the messagebox dont appear but when i select an item (other than the first item) same problem occur.

tested on ubuntu. i will try to test it in opensuse.

February 9, 2011

xeroblast xeroblast
Lab Rat
91 posts

updates : i tested it on opensuse and it produce the same problem. pressing TAB sends a signal also so it must be on focus. but when the QListWidget has already been focus, the problem will not occur anymore. only on first focus.

 
  ‹‹ QtCreator redundant for GUI development?      qmake / Makefile ››

You must log in to post a reply. Not a member yet? Register here!