Re: Gtk::Main::iteration();



Could you give me a simple example?

I try this:
                    unsigned long long FileSize;
                    char _char[1] = {0};

                    Glib::RefPtr<Gio::File> FileOut
                            = Gio::File::create_for_path(FileName);

                    Glib::RefPtr<Gio::FileInfo> FileOutInfo
                            = FileOut->query_info();

                    FileSize = FileOutInfo->get_size();


                    Glib::RefPtr<Gio::SlotAsyncReady> FileOutData;
                    //FileOut->replace_async(FileOutData, FileName);
                            

                    std::cerr << FileSize<<'\n';
                    for (unsigned long long i = 1; i <= FileSize; i++)
                    {
                       
ProgressbarStatusbarHBox.set_fraction((float)i/FileSize);
                        //FileOutData->write(_char, 1);
                    }
But it isn't working.


Mark Roberts-10 wrote:
> 
> Dear Adam!
> 
>> I have this code:
>> for (long long i = 0; i < FileSize; i++)
>> {
>>    if(Gtk::Main::events_pending())
>>        Gtk::Main::iteration();
>>
>>    fputc(_char[0], File);
>> }
>> But it is very slow. How Can speed up him?
> 
> It looks as if you were writing 'FileSize' copies of the character 
> '_char[0]' to 'File'. And you don't want your windows to stop responding, 
> so you are giving them a prod after every byte.
> 
> You don't really want to start from here.
> 
> (1) Writing a file byte by byte is unneccessarily slow, even without calls 
> to Gtk::Main::events_pending() inside the loop.
> 
> (2) Any single call to fputc() can block. For instance 'File' might be on 
> a remote filesystem and the connection might be bad or down. Your windows 
> will then stop responding, although that was what you were trying to 
> avoid.
> 
> (3) A call to Gtk::Main::iteration() can probably lead to other parts of 
> your program being executed. If you are not absolutely sure what you are 
> doing, you will shoot yourself in the foot.
> 
> The file operation should be in a seperate thread. And instead of 
> hand-coding that, you might want to use the class Gio::File from glibmm. 
> It has *async* functions one of which might suit your needs.
> 
> Hope this helps,
> Mark
> _______________________________________________
> gtkmm-list mailing list
> gtkmm-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtkmm-list
> 
> 

-- 
View this message in context: http://old.nabble.com/Gtk%3A%3AMain%3A%3Aiteration%28%29--tp27891854p27894630.html
Sent from the Gtkmm mailing list archive at Nabble.com.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]