如何使用wxThread的概念在wxListCtrl中显示大数据 [英] how to display large data in wxListCtrl with using concept of wxThread

查看:35
本文介绍了如何使用wxThread的概念在wxListCtrl中显示大数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在 wxListCtrl 中填充数据库表,我的问题是处理大范围的数据,我想借助线程概念来做到这一点,也许可以节省因为数据量大而挂起框架.我是线程概念的新手,所以你的单行对我来说就是一本书.

I'm capable to fill the database table in wxListCtrl, my problem is to handle high range of data, I want to do this with the help of thread concept , perhaps it will save to hang the frame because of high amount of data. I'm new in thread concept so your single lines will be a book for me.

我的问题是 - 如何使用 wxThread 的概念在 wxListCtrl 中显示大数据所以为此我使用了线程概念,我添加了另外两个文件 thread.c 和 thread.cpp我的入口线程代码如下所示

My question was- how to display large data in wxListCtrl with using concept of wxThread so for this I used thread concept I add two more files thread.c and thread.cpp my entry thread code is shown below

void *MyThread :: Entry()
{
    int i=1,j,k=0;
    while(i!=400)
    {
        long index=this->temp->data_list_control->InsertItem(i,wxT("amit"));
        for(j=1; j<3; j++) {
            this->temp->data_list_control->SetItem(index,j,wxT("pathak"));
        }

        k++;

        if(k==30) {
            this->Sleep(1000);
            k=0;
        }
        i++;
    }
}

有时工作正常,但是当我尝试增加 i 的值时,它会显示类似

It is sometimes working fine but when I try to increase the value of i, it shows an error like

-*showingdatainwxlistctrl: ../../src/XlibInt.c:595: _XPrivSyncFunction: Assertion `dpy->synchandler == _XPrivSyncFunction' failed.*

或者有时它会给出类似

***[Xcb] xcb_io.c:378: _XAllocID: Assertion `ret != inval_id' failed***

为什么会发生在我身上?

Why it is happening to me?

推荐答案

  1. 当您执行大量数据时,您必须在程序中使用 WXThread
  2. 首先试图从 wxEntry 点填充 wxListCtrl,这是错误的,你不能从入口点点击任何主线程控制,它没有给出错误,但这是一个错误的概念
  3. 这里需要将数据传递给handler,handler会用它来填充wxListCtrl代码看起来像这样->

  1. When you are performing high range of data you are bound to use WXThread in your program
  2. Firstly was trying to fill wxListCtrl from wxEntry point, it was wrong u can not hit any main thread control from entry point, it does not give error, but it is a wrong concept
  3. Here u need to pass the data to handler, handler will use it to fill wxListCtrl code look like this->

void *MyThread::Entry(){一个;处理程序 handler_obj;char *database_name=DATABASE_NAME;connection =handler_obj.handler(101,database_name);如果(连接==NULL){wxMessageBox(wxT("不能连接到数据库"), wxT("消息"), wxOK | wxICON_INFORMATION, NULL, -1, -1);}别的{List_Ctrl_Data list_ctrl_data_object;table_data=list_ctrl_data_object.fetch_table(connection);

void *MyThread :: Entry() { int a; Handler handler_obj; char *database_name=DATABASE_NAME; connection =handler_obj.handler(101,database_name); if(connection==NULL) { wxMessageBox(wxT("CAN NOT CONNECT TO DATABASE"), wxT("Message"), wxOK | wxICON_INFORMATION, NULL, -1, -1); } else { List_Ctrl_Data list_ctrl_data_object; table_data=list_ctrl_data_object.fetch_table(connection);

    MYSQL_ROW row;
    while((row=mysql_fetch_row(table_data))!=NULL)
        {

            wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, 100000 );
            void *row_data;
            row_data=(void *)row;
            event.SetClientData(row_data);
            temp->GetEventHandler()->AddPendingEvent( event );
            this->Sleep(1000);
        }
}

}

处理我们将使用的行数据

to handle the row data we will use

void Id_Search_Report::onNumberUpdate(wxCommandEvent& evt)
    {
        int j;
        void* hold_row;
        hold_row=(void *)evt.GetClientData();
        MYSQL_ROW row;
        row=(MYSQL_ROW)hold_row;

            const char* chars1 = row[0];
            wxString mystring1(chars1, wxConvUTF8);
            long index=data_list_control->InsertItem(this->counter,mystring1);
        this->counter++;
            for(j=1;j<12;j++)
                {
                const char* chars2=row[j];
                wxString mystring2(chars2,wxConvUTF8);
                data_list_control->SetItem(index,j,mystring2);
                }

    }

线程正在返回一行,该方法将处理该行并填充 ListCtrl ,这是填充 wxListCtrl 的正确方法.

thread is returning a row , this method will handle the row and fill ListCtrl , it is a proper way to fill wxListCtrl.

这篇关于如何使用wxThread的概念在wxListCtrl中显示大数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆