Hey Guy,

2009/8/31 Guy Deleeuw <[email protected]>:
> Hello,
>
> Ext::ComboBox.currentIndex() crash.
> With this combobox I use :
>  Ext::ComboBox* m_cbbExtContact = new Ext::ComboBox(0);
>  m_cbbExtContact->setTextSize(60);
>  m_cbbExtContact->setModel(m_pModel);
>  m_cbbExtContact->setModelColumn(1);
>
>  m_cbbExtContact->setEditable(true);
>  m_cbbExtContact->setQueryDelay(2);
>  m_cbbExtContact->setMinQueryLength(1);

Perhaps you see a crash because currentIndex() may be -1: when the
user has added an entry by editing, this entry is not added to the
underlying model. When this entry is the currently selected entry,
currentIndex() will be -1, and currentText() will return the value.

At least the test case in attachment works well for me, if not for
you, can you modify it to reproduce the crash ?

Regards,
koen
#include <Wt/WApplication>
#include <Wt/WPushButton>
#include <Wt/Ext/ComboBox>
#include <Wt/WStandardItem>
#include <Wt/WStandardItemModel>

using namespace Wt;

class TestApp : public WApplication
{
public:
  TestApp(const WEnvironment& env) : WApplication(env)
  {
    WStandardItemModel *m_pModel = new WStandardItemModel(5, 5);

    for (int i = 0; i < 5; ++i) {
      m_pModel->setItem(i, 1, new WStandardItem
			("Value" + boost::lexical_cast<std::string>(i)));
    }

    m_cbbExtContact = new Ext::ComboBox(root());
    m_cbbExtContact->setTextSize(60);
    m_cbbExtContact->setModel(m_pModel);
    m_cbbExtContact->setModelColumn(1);

    m_cbbExtContact->setEditable(true);
    m_cbbExtContact->setQueryDelay(2);

    int i = m_cbbExtContact->currentIndex();

    WPushButton *b = new WPushButton("Read it", root());

    b->clicked().connect(this, &TestApp::foo);
  }

  void foo() {
    std::cerr << m_cbbExtContact->currentIndex() << " "
	      << m_cbbExtContact->currentText() << std::endl;
  }

private:
  Ext::ComboBox *m_cbbExtContact;

};

WApplication *createApplication(const WEnvironment& env)
{
  TestApp *app = new TestApp(env);

  return app;
}

int main(int argc, char *argv[])
{
  return WRun(argc, argv, &createApplication);
}
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest

Reply via email to