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
Servidor de Backup com Ubuntu Server 24.04 LTS, RAID e Duplicati (Dell PowerEdge T420)
Visualizar câmeras IP ONVIF no Linux sem necessidade de instalar aplicativos
Atualizar Debian Online de uma Versão para outra
Instalar driver Nvidia no Debian 13
Redimensionando, espelhando, convertendo e rotacionando imagens com script
Debian 13 Trixie para Iniciantes
Convertendo pacotes DEB que usam ZSTD (Padrão Novo) para XZ (Padrão Antigo)
Debian 13 "trixie&... lançado! (44)
Rust é o "C da nossa geração"? (3)
Gerenciador de arquivos é finalizado ao abrir pasta específica (2)