Serializing a widget
-
Regarding the update of my scroollArea, I don't want to add elements but rather delete completely what it already contains.
then for the messages I want my application to run all over the platform but first on Pc using the windows operating system.
for my clients, I use TCP/ip protocol so with QTcpSocket class
-
The most elegant would likely be to have the messages stored in a model and then have a custom QStyledItemDelegate to paint whatever you want.
Again: how are you client talking to each other ? Through a central server ? How do they know each other ?
-
In fact I want to make sure that if we send a message to a client that is not connected, that this client sees the message that has been sent as soon as it is connected.
@EL-jos said in Serializing a widget:
I want to make sure that if we send a message to a client that is not connected, that this client sees the message that has been sent as soon as it is connected.
Then the central server must store the message. When the client comes online, the server can deliver the message to the client.
Note: This concept is about communications architecture. This is not related to widgets at all.
-
ahhhhh yes you're right, so I can store the message in a database at the server level then as soon as the concerned client is connected the server will be able to restore the message then send it to the client, thank you very much.
then a second unresolved problem so far;
here I have a scrollArea which first contains many widgets of different type, so I want to delete either empty all these widgets and left the scrollArea blank so without element,
how do I do that? -
ahhhhh yes you're right, so I can store the message in a database at the server level then as soon as the concerned client is connected the server will be able to restore the message then send it to the client, thank you very much.
then a second unresolved problem so far;
here I have a scrollArea which first contains many widgets of different type, so I want to delete either empty all these widgets and left the scrollArea blank so without element,
how do I do that?@EL-jos said in Serializing a widget:
here I have a scrollArea which first contains many widgets of different type, so I want to delete either empty all these widgets and left the scrollArea blank so without element,
how do I do that?Have a read through http://doc.qt.io/qt-5/qscrollarea.html . Do you see anything that might do what you want?
-
I just read and reread the Qt documentation for the QScrollArea class or even its mother classes but I can't find the solution to my problem because there is not a function that allows to remove all widgets contained in a scrollAreea
@EL-jos
Hi
Are the widgets not in a layout ?
You can clear layout withvoid clearLayout(QLayout *layout) QLayoutItem *item; while((item = layout->takeAt(0))) { if (item->layout()) { clearLayout(item->layout()); delete item->layout(); } if (item->widget()) { delete item->widget(); } delete item; } }
-
Thank you for your code.
theoretically it works but not in practice according to my example, here is a little project I created to test your code:[7_1535474695539_fenetre1.cpp](Uploading 100%) [6_1535474695538_fenetre1.h](Uploading 100%) [5_1535474695538_fenetresecond.cpp](Uploading 100%) [4_1535474695537_fenetresecond.h](Uploading 100%) [3_1535474695537_fenetresecond.ui](Uploading 100%) [2_1535474695537_main.cpp](Uploading 100%) [1_1535474695535_Oc.pro](Uploading 100%) [0_1535474695483_Oc.pro.user](Uploading 100%)
-
sorry I can't send my project on topic, send me your E-mail address so I can send it to you by E-mail
@EL-jos
Sorry i dont have email i use for Qt forum.
You can use dropbox or google drive.
Are you sure u give it the correct layout ?
Im sure code works so maybe its other layout u clear that u think.
also use the debugger to see what happens. -
Yes thank you sorry it was a small mistake on my part and there it works correctly, here is the code:
void Controleur::on_pushButton_clicked() { QLayoutItem *item; int nb = 3; int a = 0; qDebug() << nb; while(ui->scrollAreaWidgetContents->layout()->count() > 0){ for(int i = 0; i < ui->scrollAreaWidgetContents->layout()->count(); ++i){ item = ui->scrollAreaWidgetContents->layout()->takeAt(i); if(item->layout()){ qDebug("It's a layout"); delete item->layout(); } if(item->widget()){ qDebug("It's a widget"); delete item->widget(); } delete item; } qDebug() << "suppression N°" << a; ++a; } }
-
Yes thank you sorry it was a small mistake on my part and there it works correctly, here is the code:
void Controleur::on_pushButton_clicked() { QLayoutItem *item; int nb = 3; int a = 0; qDebug() << nb; while(ui->scrollAreaWidgetContents->layout()->count() > 0){ for(int i = 0; i < ui->scrollAreaWidgetContents->layout()->count(); ++i){ item = ui->scrollAreaWidgetContents->layout()->takeAt(i); if(item->layout()){ qDebug("It's a layout"); delete item->layout(); } if(item->widget()){ qDebug("It's a widget"); delete item->widget(); } delete item; } qDebug() << "suppression N°" << a; ++a; } }
-
Hi,
I'm sorry I'm not here;
Yes, I just wanted to remove the widgets, not the layout.I take this opportunity to ask a question I don't understand.
here is the server and client code:- Server
QTcpServer *serveur = new QTcpServer(this); iserveur->listen(QHostAddress::Any, 50885);
- client
QTcpSocket *socket = new QTcpSocket(this); socket->abort(); socket->connectToHost("127.0.0.1", 50885);
so we understand that my server accepts any type of address, such as: Local IP, Internal IP and Internet IP.
but strangely as soon as I execute my code, the server accepts that the local IP: 127.0.0.1 and the internal IP: 192.168.X.X, as far as the internet IP is concerned this does not pass and there is a message telling me time is out.do you know how I can connect to the server via Internet IP?
-
Check your network and firewall settings.
-