Guest User

mainwindow.cpp

a guest
Feb 6th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3.  
  4. QString display_static_text(){
  5.     return "This is a test";
  6. }
  7.  
  8. QString display_from_file(){
  9.     QString path = QDir::homePath() + "/fun";
  10.     QString text;
  11.     QFile file(path);
  12.     KAuth::Action action = KAuth::Action("org.kde.auth.trial.read");
  13.     KAuth::ExecuteJob *job = action.execute();
  14.     bool success = job->exec();
  15.  
  16.     if(success){
  17.         if(file.open(QIODevice::ReadOnly)){
  18.             text = file.readAll();
  19.         }else{
  20.             text = file.errorString() + " " + path;
  21.         }
  22.     }else{
  23.         text = job->errorString();
  24.     }
  25.  
  26.     return text;
  27. }
  28.  
  29. void MainWindow::display_text(){
  30.     display->setText(display_from_file());
  31. }
  32.  
  33. MainWindow::MainWindow(QWidget *parent) :
  34.     QMainWindow(parent),
  35.     ui(new Ui::MainWindow)
  36. {
  37.     ui->setupUi(this);
  38.     QString text = display_static_text();
  39.  
  40.     display_text_button = new QPushButton("Show Text");
  41.  
  42.     connect(display_text_button,SIGNAL(clicked(bool)),this,SLOT(display_text()));
  43.  
  44.     display = new QLabel;
  45.     display->setText(text);
  46.  
  47.     main_layout = ui->mainLayout;
  48.     main_layout->addWidget(display);
  49.     main_layout->addWidget(display_text_button);
  50. }
  51.  
  52. MainWindow::~MainWindow()
  53. {
  54.     delete ui;
  55. }
Add Comment
Please, Sign In to add comment