Tips on design and better usage of QT
-
Hi,
i have this function :
@
void Signatures::read_pcaps_path();
@that is called by signal , meaning when some button is clicked it triggers a signal and this function is the handler of that signal.
inside this function i want to call a function in other thread , this function is :
@
void upload_multiple_files_to_ftp(ACS_session acs_session,QStringList file_paths,QTextEdit*& console);
@
how i call it :
@
QFuture<void> future = QtConcurrent::run(upload_multiple_files_to_ftp,acs_session, file_paths,ui->console);
@
notice the "ui->console" which is a QTextEdit that i have to send it to the upload_multiple_files_to_ftp function because it is not in the Signatures:: class where there is the ui->console .This code works , but i get the output :
[quote]
QObject::connect: Cannot queue arguments of type 'QTextBlock'
(Make sure 'QTextBlock' is registered using qRegisterMetaType().)
QObject::connect: Cannot queue arguments of type 'QTextCursor'
(Make sure 'QTextCursor' is registered using qRegisterMetaType().)
[/quote]is this the best way to call a function in other thread and in that thread do some actions sequentially?
what i mean is that in the upload_multiple_files_to_ftp function (which is run in other thread) i upload files one after the other each upload is a blocking function because i want to know if the uploading is done successfully before moving to the next one . -
Hi,
@QTextEdit*& console@
*&: is it a typo ?
The problem is not the sequence. You are trying to transmit over signal and slots an unknown type. Anyway you are also trying to update a GUI element directly from another thread which is not possible. That requires signal and slots.
-
Hi,
yeah its a typo xD , but the GUI element does get updated .
as for the signal,slot , how do i do that ? since the upload_multiple_files_to_ftp is a static function not in any class . -
Did you considered the use of "QFuture":http://doc.qt.io/qt-5/qfuture.html#details ?