アプリケーションのメインウィンドウのタイトルの名前を変更しようとしていますが、名前を変更しようとすると、名前が切り捨てられます。変換の問題かどうかを確認しようとしましたが、なぜこれが発生するのか本当にわかりません。この小さなプログラムを試してみてください。キャンセルを押すと、タイトルバーにデフォルトのアプリケーション名が表示されますが、ファイルを選択すると、ファイルの最初の行がタイトルとして表示されますが、代わりに切り捨てられます...文字列の終わりの前に常に3文字の文字列が表示されます、および3つのドット「...」が追加されます。
私は何が間違っているのですか?それとも私のgtkmmバージョンか何かのバグですか?私はgtkmm-2.4を使用しています。よろしくお願いします。
#include <iostream>
#include <gtkmm.h>
using namespace std;
using namespace Gtk;
using namespace Glib;
class AppWindow : public Window {
public:
AppWindow();
protected:
void onMenuFileOpen();
private:
ustring app_name;
void OpenScript(const ustring sScriptFile);
};
AppWindow::AppWindow() {
app_name = "default app_name, very long name, with !!^spectal caractères à afficher, and there is no name truncation";
//set_title(app_name);
set_default_size(600, 600);
onMenuFileOpen();
}
void AppWindow::onMenuFileOpen() {
FileChooserDialog dialog("Choose a file", FILE_CHOOSER_ACTION_OPEN);
dialog.set_transient_for(*this);
//Add response buttons the the dialog:
dialog.add_button(Stock::CANCEL, RESPONSE_CANCEL);
dialog.add_button(Stock::OPEN, RESPONSE_OK);
//Plain text filter
FileFilter filter_text;
filter_text.set_name("plain text");
filter_text.add_mime_type("text/plain");
dialog.add_filter(filter_text);
//Show the dialog and wait for a user response:
if(dialog.run() == RESPONSE_OK) {
OpenScript(dialog.get_filename());
}
//HERE, I RENAME THE WINDOW
set_title(app_name);
cout << app_name << endl;
}
void AppWindow::OpenScript(const ustring sScriptFile) {
RefPtr<IOChannel> file = IOChannel::create_from_file(sScriptFile,"r");
IOStatus status;
ustring one_line;
if(file->get_flags() & IO_FLAG_IS_READABLE) {
status = file->read_line(one_line);
app_name=one_line;
}
file->close();
}
int main(int argc, char *argv[]) {
Main kit(argc, argv);
AppWindow window;
//Shows the window and returns when it is closed.
Main::run(window);
return 0;
}