Results 1 to 3 of 3

Thread: QApplication::clipboard not read textCursor cut

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QApplication::clipboard not read textCursor cut

    1- If i cut text on QTextEdit subclass ...
    QClipboard *netag = QApplication::clipboard();
    QString textclip = netag->text(QClipboard::Selection);

    QClipboard cant not read null string .... why?

    2- If i take text from TextEdit::keyPressEvent(QKeyEvent *e)

    QTextCursor tabact = textCursor();
    QString actual = tabact.selectedText();

    can read is ok but on console newline ("\n") are on unknow char (?) and

    QStringList line = actual.split("\n"); can not split . why? only one line result if select 2 or more line...



    Qt Code:
    1. void TextEdit::IndentText(const QString text , int x )
    2. {
    3. const QChar Nline('\n');
    4.  
    5. QClipboard *netag = QApplication::clipboard();
    6. QString textclip = netag->text(QClipboard::Selection);
    7.  
    8. QStringList line = textclip.split(Nline);
    9. QStringList newline;
    10. for (int i = 0; i < line.size(); ++i) {
    11. QString onel = QString("\t%1").arg(line.at(i));
    12. newline.append(onel);
    13. }
    14.  
    15. qDebug() << "### line!!! " << line.size(); /* not correct */
    16. const QString reformat = newline.join(Nline);
    17.  
    18. netag->clear();
    19. netag->setText(reformat);
    20. paste();
    21. }
    22.  
    23. void TextEdit::keyPressEvent(QKeyEvent *e)
    24. {
    25.  
    26. if (e->key() == Qt::Key_Tab) {
    27.  
    28. QTextCursor tabact = textCursor();
    29. int stabstart = tabact.selectionStart();
    30. int stabstop = tabact.selectionEnd();
    31. const QString actual = tabact.selectedText();
    32. if (actual.size() > 3) {
    33. IndentText(actual,1);
    34. cut();
    35. qDebug() << "### stabstart " << stabstart;
    36. qDebug() << "### stabstop " << stabstart;
    37. return;
    38. }
    39. }
    To copy to clipboard, switch view to plain text mode 
    Attached Files Attached Files

Similar Threads

  1. QIODevice read()
    By ShaChris23 in forum Newbie
    Replies: 1
    Last Post: 3rd May 2007, 00:29
  2. How to Read and display BMP image using QT
    By agsrinivasan in forum Qt Programming
    Replies: 3
    Last Post: 29th January 2007, 07:14
  3. Increasing QProcess read performance
    By mcostalba in forum Qt Programming
    Replies: 9
    Last Post: 4th December 2006, 20:12
  4. How to read line from file
    By Krishnacins in forum Newbie
    Replies: 10
    Last Post: 1st June 2006, 23:14
  5. Replies: 13
    Last Post: 1st June 2006, 14:01

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.