c++ - 将字符串从 Glib::ustring 转换为 double - gtkm 2

标签 c++ casting glib gtkmm

我正在用 gtkmm 2 开发一个 C++ 应用程序

我在将字符串从 entryfield 转换为 double(或 int)时遇到问题。

我得到以下编译错误

 cannot convert from Glib::ustring to double

输入框

 interestrate.set_max_length(50);
interestrate.set_text(interestrate.get_text() );
interestrate.select_region(0, interestrate.get_text_length());
m_box1.pack_start(interestrate);
interestrate.show();

按钮

m_button3.signal_clicked().connect(sigc::bind<-1, Glib::ustring>(
    sigc::mem_fun(*this, &HelloWorld::on_button_clicked), "OK"));

m_box1.pack_start(m_button3);
m_button3.show();

和事件处理器

 void HelloWorld::on_button_clicked(Glib::ustring data)
 {
  std::cout << "interestrate: " << interestrate.get_text() << std::endl; 
 }

所以我想得到双倍的返回值

 interestrate.get_text()

最佳答案

没想到这么简单

 std::string s = interestrate.get_text();
 double d = atof(s.c_str());

关于c++ - 将字符串从 Glib::ustring 转换为 double - gtkm 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24139961/

相关文章:

c++ - 如何期望来自重定向和用户输入的输入

c++ - 不支持扩展 'GL_ARB_shading_language_420pack',如何在QT中加载此扩展?

C++/Mysql 连接器 : undefined reference to `get_driver_instance'

c++ - C++ 中的两阶段隐式转换

c - 为什么在未设置 DBUS_SESSION_BUS_ADDRESS 时 g_file_copy 返回 Operation not supported

c++ - 如何在 C++ 中打印模板类型名?

c# - 我如何为我的类(class)提供定制类型转换支持?

java - java中未经检查的分配

c - 我无法通过 g_hash_table_look_up() 获得结果

python - 如何使用 libchamplain 在 Python 中加载本地瓦片或 OSM XML?