Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "widget.h"
  2. #include "ui_widget.h"
  3.  
  4. #include <QDebug>
  5. #include <QRegExp>
  6.  
  7. Widget::Widget(QWidget *parent) :
  8.     QWidget(parent),
  9.     ui(new Ui::Widget) {
  10.  
  11.     ui->setupUi(this);
  12. }
  13.  
  14. Widget::~Widget()
  15. {
  16.     delete ui;
  17. }
  18.  
  19. void Widget::on_textBrowser_anchorClicked(const QUrl &url) {
  20.     qDebug() << url.toString() << "clicked";
  21. }
  22.  
  23. void Widget::on_pushButton_clicked() {
  24.     auto text = ui->lineEdit->text();
  25.     if (text.isEmpty()) {
  26.         return;
  27.     }
  28.  
  29.     QRegExp rx("((?:https?|ftp)://\\S+)", Qt::CaseInsensitive);
  30.     text.replace(rx, "<a href=\"\\1\">\\1</a>");
  31.     ui->textBrowser->append(text);
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement