Solved connect: No such signal QPlainTextEdit::textChanged(QByteArray&) in serial.cpp:48
-
I am recently started coding for serialport communication where i taken refererence of qtserialport terminal example code and there another console class is taken where i haven't taken that instead i directly trying to use qplaintextedit in ui file . where i am getting read data properly but writing is nit getting so there in connect method i did this way.
in serial.h file:
QPlainTextEdit *console.
in serial.cpp
console=new QPlainTextEdit ()
connect(console, SIGNAL(textChanged(QByteArray&)), this, SLOT(writeData(QByteArray)));
by using this way when compiled i am getting this message on desktop.
connect: No such signal QPlainTextEdit::textChanged(QByteArray&)
why iam getting this is the way i am using is correct?
are like readyread any default signals for QPlianTextEdit class to write in to textbox and create a connection to slot methos . -
Thank you all for your support .
Somehow i managed in completing the application using emiting signal from a keypressevent method. it worked for me with little condition that until we keep cursor in plaintextedit box it will continue writing but once if we place the cursor it is failng to write and then it works normal as plaintextedit where only we can write in to box but cannot write to serialport
I am working on it how to solve so as of now for these i am closing this belt as solved -
Because
textChanged
signal doesn't has a QByteArray as parameter.
And the problem here is not that QPlainTextEdit doesn't have a "readyRead" signal, but it doesn't have a "read"-like function to read the "unread" data.
If you use a QPlainTextEdit instead of a console, you'll need to detect what has changed by your own.If this is my project, I think I would use a read-only QPlainTextEdit just as a history viewer, and a QLineEdit as input, connecting its
returnPressed
signal. -
Thank you Bonnie for your reply.
So You mean to say that i cannot use QByteArray as a parameter in PlainTextEdit. so can i use this way connect(ui->PlainTextEdit,SIGNAL(textChanged(QString)),this,SLOT(writeData(QByteArray)))?
this also gives as this way
No such signal is coming.
As you said how to use line edit along with plaintextedit.
OR
is there any way to add custom signals created to Qplaintextedit class.
OR
can i use source object of widget and signal of custom signal we are emiting
like this way :
connect(ui->plainTextEdit,SIGNAL(Serial::getData()),this,SLOT(writeData(QByteArray))); -
@Lavanya said in connect: No such signal QPlainTextEdit::textChanged(QByteArray&) in serial.cpp:48:
so can i use this way connect(ui->PlainTextEdit,SIGNAL(textChanged(QString)),this,SLOT(writeData(QByteArray)))?
You cannot. See https://doc.qt.io/qt-5/signalsandslots-syntaxes.html
The important points are:
- When you connect using the
SIGNAL()
andSLOT()
macros, the datatypes must match exactly. You cannot use this to connect anint
signal to adouble
slot. - When you connect using function pointers, the datatypes can be different -- as long as the signal datatype can be automatically converted to the slot datatype. You can use this to connect an
int
signal to adouble
slot. - QString cannot be automatically converted to a QByteArray, so there is no way to connect a
QString
signal to aQByteArray
slot.
What you can do instead is connect the signal to a lambda function:
connect(console, &QPlainTextEdit::textChanged, [this](const QString &newText) { this->writeData(newText.toUtf8()); });
- When you connect using the
-
If i am creating a object to QPlainTextEdit and creating new to that in cpp file and calling that object directly in connect method is giving me like this.
QObject::connect: Incompatible sender/receiver arguments
well which is not case if i used ui->plaintextedit in connect?
Anybody can tell me about this? -
@Lavanya Please show your code, it is hard to understand what you mean.
-
@JKSH said in connect: No such signal QPlainTextEdit::textChanged(QByteArray&) in serial.cpp:48:
connect(console, &QPlainTextEdit::textChanged, [this](const QString &newText) {
this->writeData(newText.toUtf8());
});Since
void QPlainTextEdit::textChanged()
have no parameter at all, I think that cannot be done either... -
@Bonnie said in connect: No such signal QPlainTextEdit::textChanged(QByteArray&) in serial.cpp:48:
@JKSH said in connect: No such signal QPlainTextEdit::textChanged(QByteArray&) in serial.cpp:48:
connect(console, &QPlainTextEdit::textChanged, [this](const QString &newText) {
this->writeData(newText.toUtf8());
});Since
void QPlainTextEdit::textChanged()
have no parameter at all, I think that cannot be done either...Oops, good spot.
Easily fixed:
connect(console, &QPlainTextEdit::textChanged, [console, this] { this->writeData( console->text().toUtf8() ); });
-
@JKSH said in connect: No such signal QPlainTextEdit::textChanged(QByteArray&) in serial.cpp:48:
connect(console, &QPlainTextEdit::textChanged, [console, this] {
this->writeData( console->text().toUtf8() );
});Yes! But the problem is that it will always write the full text of the QPlainTextEdit whenever there's any change.
This is what I said about QPlainTextEdit doesn't have a "read"-like function... -
@Bonnie said in connect: No such signal QPlainTextEdit::textChanged(QByteArray&) in serial.cpp:48:
But the problem is that it will always write the full text of the QPlainTextEdit whenever there's any change.
No arguments there. Nonetheless, I'd say that understanding how to use
QObject::connect()
is more fundamental -- OP will still face the same error messages even with QLineEdit. -
So more or less i have to create one more class and define a signal in that class and then create a object to that class in mainwindow class and write it in connect method . I hope this way only it seems to work with out creating too many classes in application i wanted to use directly but it creating a problem.
Nonetheless, I'd say that understanding how to use QObject::connect()
Yes i do understand but trying to create use QPlainTextEdit for writing to serial port directly and for that i am trying to use connect method to create a connection between Qplaintextedit widget object to serial port writedata method slot.
Which is very clear in my understanding but problem comes in using proper signal only. i didn't find proper signal for Qplaintextedit when something written totextedit create a connection to serialport write data. -
@Lavanya said in connect: No such signal QPlainTextEdit::textChanged(QByteArray&) in serial.cpp:48:
i have to create one more class and define a signal in that class and then create a object to that class
Why do you think so?
This was the suggestion from @JKSH :connect(console, &QPlainTextEdit::textChanged, [console, this] { this->writeData( console->text().toUtf8() ); });
I don't see any new classes/signals here...
-
Thank you all for your support .
Somehow i managed in completing the application using emiting signal from a keypressevent method. it worked for me with little condition that until we keep cursor in plaintextedit box it will continue writing but once if we place the cursor it is failng to write and then it works normal as plaintextedit where only we can write in to box but cannot write to serialport
I am working on it how to solve so as of now for these i am closing this belt as solved