Important: Please read the Qt Code of Conduct -

Dragging content of one textedit to another...??

  • hello ,
    im dragging text of one textedit say "textedit" to another textedit "textedit_2" for this im not using any drag and drop functions .this im doing in a normal way only, as and when the te2 gets text i want to send that text through tcp communication to receiver.
    here is my code...

    #include "mainwindow.h"
    #include "ui_mainwindow.h"

    MainWindow::MainWindow(QWidget *parent) :
    ui(new Ui::MainWindow)
    sendsocket = new QTcpSocket(this);
    QString hostaddress="";
    QString str=ui->textEdit_2->toPlainText();------------->//this gives nothing in receiver side//

    delete ui;

    1. You need to maintain your tcp connection correctly.
      Where the guarantee that socket is in ConnectedState when you trying to write bytes to it? You need to create slot smthg like processOnConnected() and connect "signal connected() of QTcpSocket": to this slot. And you need slot for process "error(...) signal of QTcpSocket": You can check simply can you send something though your connection "by check state": must return QAbstractSocket::ConnectedState.
    2. You always must check what returns method QTcpSocket::write - "see documentation":, it returns number of bytes written. Additionally "you can use": method instead because it'll ignore zero-terminated strings.
    3. Bad plan to maintain network logic in widgets constructor - but if it is only for practice - ok.
      Sorry for my bad english, hope this helps.

Log in to reply