Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Serializing a widget

Serializing a widget

Scheduled Pinned Locked Moved Unsolved General and Desktop
37 Posts 7 Posters 7.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    EL-jos
    wrote on 28 Aug 2018, 13:35 last edited by
    #22

    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?

    J 1 Reply Last reply 28 Aug 2018, 13:41
    0
    • E EL-jos
      28 Aug 2018, 13:35

      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?

      J Offline
      J Offline
      JKSH
      Moderators
      wrote on 28 Aug 2018, 13:41 last edited by
      #23

      @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?

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • E Offline
        E Offline
        EL-jos
        wrote on 28 Aug 2018, 14:52 last edited by
        #24

        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

        M 1 Reply Last reply 28 Aug 2018, 14:54
        0
        • E EL-jos
          28 Aug 2018, 14:52

          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

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 28 Aug 2018, 14:54 last edited by
          #25

          @EL-jos
          Hi
          Are the widgets not in a layout ?
          You can clear layout with

          void 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;
              }
          }
          
          1 Reply Last reply
          1
          • E Offline
            E Offline
            EL-jos
            wrote on 28 Aug 2018, 16:45 last edited by
            #26

            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%)

            1 Reply Last reply
            0
            • E Offline
              E Offline
              EL-jos
              wrote on 28 Aug 2018, 16:56 last edited by
              #27

              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

              M 1 Reply Last reply 28 Aug 2018, 17:18
              0
              • E EL-jos
                28 Aug 2018, 16:56

                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

                M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 28 Aug 2018, 17:18 last edited by
                #28

                @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.

                1 Reply Last reply
                0
                • E Offline
                  E Offline
                  EL-jos
                  wrote on 28 Aug 2018, 19:36 last edited by
                  #29

                  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;
                      }
                  }
                  
                  M 1 Reply Last reply 28 Aug 2018, 19:43
                  0
                  • E EL-jos
                    28 Aug 2018, 19:36

                    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;
                        }
                    }
                    
                    M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 28 Aug 2018, 19:43 last edited by
                    #30

                    @EL-jos
                    Hi
                    Ok super.
                    You also want to remove any layout it has ?
                    Normally one wish to keep layout and only remove widgets.

                    1 Reply Last reply
                    0
                    • E Offline
                      E Offline
                      EL-jos
                      wrote on 29 Aug 2018, 16:32 last edited by EL-jos
                      #31

                      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?

                      J 1 Reply Last reply 29 Aug 2018, 23:49
                      0
                      • S Offline
                        S Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 29 Aug 2018, 19:51 last edited by
                        #32

                        Check your network and firewall settings.

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0
                        • E Offline
                          E Offline
                          EL-jos
                          wrote on 29 Aug 2018, 21:16 last edited by
                          #33

                          so since I'm on windows 10 how should my firewall be?

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on 29 Aug 2018, 21:28 last edited by
                            #34

                            Please do your homework.

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            1 Reply Last reply
                            1
                            • E EL-jos
                              29 Aug 2018, 16:32

                              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?

                              J Offline
                              J Offline
                              JKSH
                              Moderators
                              wrote on 29 Aug 2018, 23:49 last edited by
                              #35

                              @EL-jos said in Serializing a widget:

                              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.

                              That's because:

                              • When your client tries to connect to a local/internal IP address, the connection stays within the same PC.
                              • When your client tries to connect to an "Internet IP" address, the connection reaches your server's Router. You must tell your Router to forward the connection to your Server PC.

                              If you want to create an application that communicates over the Internet, you must first understand the topic of Port Forwarding (e.g. https://en.wikipedia.org/wiki/Port_forwarding ). And like @SGaist said, you must configure your Server's firewall to accept the connection.

                              Note: Port Forwarding and Firewall configuration are topics outside the scope of Qt. Please do your homework and research these topics online.

                              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                              1 Reply Last reply
                              0
                              • E Offline
                                E Offline
                                EL-jos
                                wrote on 30 Aug 2018, 19:36 last edited by
                                #36

                                Yes you are right but except I just allowed my application to communicate through the windows firewall (public and private) but the client still can't connect to the server via ip/internet.

                                Please help me.

                                here is my example code:

                                
                                Controleur::Controleur(QWidget *parent) :
                                    QDialog(parent)
                                {
                                    setupUi(this);
                                
                                    serveur = new QTcpServer(this);
                                    QObject::connect(serveur,SIGNAL(newConnection()),this,SLOT(on_newConnection()));
                                
                                    client = new QTcpSocket(this);
                                    QObject::connect(client,SIGNAL(connected()),this,SLOT(on_connected()));
                                    QObject::connect(client,SIGNAL(stateChanged(QAbstractSocket::SocketState socketState)),this,SLOT(on_stateChanged(QAbstractSocket::SocketState socketState)));
                                    QObject::connect(client,SIGNAL(error(QAbstractSocket::SocketError socketError)),this,SLOT(on_error(QAbstractSocket::SocketError socketError)));
                                }
                                
                                
                                void Controleur::on_newConnection(){
                                
                                    qDebug("New connection");
                                }
                                
                                void Controleur::on_pushButton_clicked()
                                {
                                    // dem. serveur
                                
                                    serveur->listen(QHostAddress::AnyIPv4,40885);
                                
                                    if(serveur->isListening())
                                        qDebug("The server is ready for listening");
                                    if(!serveur->isListening())
                                        qDebug("The server is not listening");
                                
                                }
                                
                                void Controleur::on_pushButton_2_clicked()
                                {
                                    // con. client
                                
                                    client->abort();
                                    client->connectToHost("196.92.6.87",50885);
                                    qDebug("Attempt to connect to the server...");
                                
                                }
                                
                                
                                J 1 Reply Last reply 31 Aug 2018, 02:12
                                0
                                • E EL-jos
                                  30 Aug 2018, 19:36

                                  Yes you are right but except I just allowed my application to communicate through the windows firewall (public and private) but the client still can't connect to the server via ip/internet.

                                  Please help me.

                                  here is my example code:

                                  
                                  Controleur::Controleur(QWidget *parent) :
                                      QDialog(parent)
                                  {
                                      setupUi(this);
                                  
                                      serveur = new QTcpServer(this);
                                      QObject::connect(serveur,SIGNAL(newConnection()),this,SLOT(on_newConnection()));
                                  
                                      client = new QTcpSocket(this);
                                      QObject::connect(client,SIGNAL(connected()),this,SLOT(on_connected()));
                                      QObject::connect(client,SIGNAL(stateChanged(QAbstractSocket::SocketState socketState)),this,SLOT(on_stateChanged(QAbstractSocket::SocketState socketState)));
                                      QObject::connect(client,SIGNAL(error(QAbstractSocket::SocketError socketError)),this,SLOT(on_error(QAbstractSocket::SocketError socketError)));
                                  }
                                  
                                  
                                  void Controleur::on_newConnection(){
                                  
                                      qDebug("New connection");
                                  }
                                  
                                  void Controleur::on_pushButton_clicked()
                                  {
                                      // dem. serveur
                                  
                                      serveur->listen(QHostAddress::AnyIPv4,40885);
                                  
                                      if(serveur->isListening())
                                          qDebug("The server is ready for listening");
                                      if(!serveur->isListening())
                                          qDebug("The server is not listening");
                                  
                                  }
                                  
                                  void Controleur::on_pushButton_2_clicked()
                                  {
                                      // con. client
                                  
                                      client->abort();
                                      client->connectToHost("196.92.6.87",50885);
                                      qDebug("Attempt to connect to the server...");
                                  
                                  }
                                  
                                  
                                  J Offline
                                  J Offline
                                  JKSH
                                  Moderators
                                  wrote on 31 Aug 2018, 02:12 last edited by JKSH
                                  #37

                                  @EL-jos said in Serializing a widget:

                                  I just allowed my application to communicate through the windows firewall (public and private) but the client still can't connect to the server via ip/internet.

                                  Read my previous post again about Routers and Port Forwarding. The problem is not in your code.

                                  Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                                  1 Reply Last reply
                                  2

                                  31/37

                                  29 Aug 2018, 16:32

                                  • Login

                                  • Login or register to search.
                                  31 out of 37
                                  • First post
                                    31/37
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • Users
                                  • Groups
                                  • Search
                                  • Get Qt Extensions
                                  • Unsolved