Gtkmm and thread's question?
- From: lovelinux <xiaoaojianghu_ai 163 com>
- To: gtkmm-list gnome org
- Subject: Gtkmm and thread's question?
- Date: Sun, 26 Oct 2008 03:36:28 -0700 (PDT)
code:
tg.cpp
#include <gtkmm/main.h>
#include <glibmm/thread.h>
#include "MainFrame.h"
int main(int argc,char** argv)
{
Glib::thread_init();
Gtk::Main kit(argc,argv);
MainFrame mainframe;
Gtk::Main::run(mainframe);
return 0;
}
MainFrame.h
#include <glibmm/thread.h>
#include <gtkmm/window.h>
#include <gtkmm/box.h>
#include <gtkmm/button.h>
#include <gtkmm/messagedialog.h>
class MainFrame : public Gtk::Window
{
public:
MainFrame();
virtual ~MainFrame();
private:
Gtk::VBox m_vbox;
Gtk::Button m_button;
Glib::Thread* m_thread;
sigc::connection conn;
protected:
bool on_delete_event(GdkEventAny* event);
void on_clicked();
void on_timer();
};
MainFrame.cpp
#include <gtkmm/stock.h>
#include "MainFrame.h"
MainFrame::MainFrame() :m_button(Gtk::Stock::OK){
// TODO Auto-generated constructor stub
set_title("ThreadGUI");
set_size_request(450,500);
set_resizable(false);
add(m_vbox);
m_button.signal_clicked().connect(sigc::mem_fun(*t
his,&MainFrame::on_clicked));
m_vbox.pack_start(m_button,false,false);
show_all();
}
MainFrame::~MainFrame() {
// TODO Auto-generated destructor stub
conn.disconnect();
}
void MainFrame::on_clicked(){
m_thread=Glib::Thread::create(sigc::mem_fun(*this,
&MainFrame::on_timer),true);
//conn = Glib::signal_timeout().connect(sigc::mem_fun(*this ,
&MainFrame::on_timer),10000 );
}
void MainFrame::on_timer(){
Gtk::Window *window;
window=(Gtk::Window*)(get_toplevel());
Gtk::MessageDialog dlg(*window,"ok!");
dlg.set_title("ThreadGUI");
dlg.run();
}
bool MainFrame::on_delete_event(GdkEventAny* event){
return false;
}
build is success,but running begin thread is error:
Locking assertion failure Backtrace.............
--
View this message in context: http://www.nabble.com/Gtkmm-and-thread%27s-question--tp20172057p20172057.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]