Enviado em 20/10/2017 - 22:09h
Boa noite a todos,#include <iostream>
#include <thread>
#include <unistd.h>
#include <gtkmm.h>
void imprimir(bool *estado, Gtk::TextView *visao_de_texto, Glib::RefPtr <Gtk::TextBuffer> buffer_de_texto)
{
for ( size_t segundos = 1;
*estado;
segundos++ )
{
sleep(1);
buffer_de_texto->insert(buffer_de_texto->end(), std::string("Dormir ") + std::to_string(segundos) + std::string(" segundos...\n"));
// Minha tentativa
visao_de_texto->scroll_to(buffer_de_texto->get_insert(), 0, 0, 0);
}
}
int main(int argc, char *argv[])
{
Glib::RefPtr <Gtk::Application> aplicacao = Gtk::Application::create(argc, argv, "Exemplo.com");
// TextBuffer
Glib::RefPtr <Gtk::TextBuffer> buffer_de_texto = Gtk::TextBuffer::create();
// TextView
Gtk::TextView visao_de_texto;
visao_de_texto.property_editable() = false;
visao_de_texto.set_buffer(buffer_de_texto);
visao_de_texto.show();
// ScrolledWindow
Gtk::ScrolledWindow janela_de_rolamento;
janela_de_rolamento.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
janela_de_rolamento.add(visao_de_texto);
janela_de_rolamento.show();
// Window
Gtk::Window janela;
janela.set_default_size(320, 240);
janela.add(janela_de_rolamento);
janela.show();
// Thread
bool estado = true;
std::thread thread(imprimir, &estado, &visao_de_texto, buffer_de_texto);
// Resultado
int resultado = aplicacao->run(janela);
estado = false;
thread.join();
return resultado;
}
g++ -O2 -std=c++11 -pedantic-errors -Wall -Werror -Wextra -fstack-protector-all -pthread `pkg-config --cflags --libs gtkmm-3.0` teste.cpp -o teste.run
Aprenda a Gerenciar Permissões de Arquivos no Linux
Como transformar um áudio em vídeo com efeito de forma de onda (wave form)
Como aprovar Pull Requests em seu repositório Github via linha de comando
Dando - teoricamente - um gás no Gnome-Shell do Arch Linux
Como instalar o Google Cloud CLI no Ubuntu/Debian
Mantenha seu Sistema Leve e Rápido com a Limpeza do APT!
Procurando vídeos de YouTube pelo terminal e assistindo via mpv (2025)