Couldn't retrive information about entry xyz in listbox

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
norisknodisk
Knows some wx things
Knows some wx things
Posts: 43
Joined: Fri Sep 13, 2013 10:24 am

Couldn't retrive information about entry xyz in listbox

Post by norisknodisk »

Hello,

I have written a piece of code that opens a txt file, reads in the dataset inside it and saves it in a sqlite3 db.
The entries of the database are also shown in a wxListCtrl.

Later on, after the user has added more datasets to the textfile, I want him to be able to open it again with my programme, which should recognise the new entries and add them to the existing database. <- I already got that all more or less working.

However, the problem is that after I have added the new entries to the listctrl, they are: a) not shown, till I explicitly redraw the window and b) I always get the error:
"Couldn't retrive information about entry x in listbox" for every new element that the programme has found in the txt file. (so lets say it found four new entries, I get four errors for them.)

I followed my function in the debugger up until the point where it goes into the wxApp and other internals - without the error flagging up - I also tried deleting all elements in the listctrl and then inserting them again into the listctrl, but i still get the same error.

I don't know if it helps to find the problem but I still added the piece of code:

Code: Select all


bool X::update_db(wxListCtrl* _listbox){
wxListCtrl* org_listbox = _listbox;
	
	if(org_listbox->GetItemCount()<list.size()-1)
	{
		for(int x=0;x<list.size()-1;x++)
		{
			if(org_listbox->GetItemText(x,0)!=list[x])
			{
				wxString maskA = "<p align=\"center\"><font face=\"Segoe UI\"size=\" size=\"style=\" color=\"#000000\" >";
				maskA.append(list[x]);
				maskA.append("</font>");

				wxString maskB = "<!empty>";

				wxString tmp_query = // some sql query
				parent->current_db.query(tmp_query.wc_str());	
			}
		}
		org_listbox->DeleteAllItems();
		parent->edit_entry->fill_columns();
	}
}
I read somewhere else in the forum that it could have something to do with two threads trying to access the same ressource / my listctrl at the same time, but I am fairly new to threads and don't really know how to prohibit an unknown thread from accessing my listctrl + it might not even be a thread issue as i didn'T specifially start a new thread.

Any ideas how to get rid of those mistakes ? should i post more src code ?
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Couldn't retrive information about entry xyz in listbox

Post by doublemax »

Code: Select all

if(org_listbox->GetItemCount()<list.size()-1)
   {
      for(int x=0;x<list.size()-1;x++)
      {
         if(org_listbox->GetItemText(x,0)!=list[x])
The error message seems clear. If your old list_ctrl has 10 entries and the new data in "list" contains 14, you will still try to access elements 11-14 from the list_ctrl - which don't exist.
Use the source, Luke!
norisknodisk
Knows some wx things
Knows some wx things
Posts: 43
Joined: Fri Sep 13, 2013 10:24 am

Re: Couldn't retrive information about entry xyz in listbox

Post by norisknodisk »

thanks... why didn't i see that myself :oops:
Post Reply