title: How to create model in a QT MVC application
body: <p>I got three little program. One is MessageGenerator (In which I create new text message), next is MessageStorage (server running in background, which has std::vector for holding new objects) and MessageViewer (this should be a view-model for displaying objects from std::vector from server). The problem is that I don't know how to do it. I understand that I should create some model and pass to him my std::vector from server, but how to do it ??? </p>
  
  <p>Apache thrift file</p>
  
  <pre><code>struct Log
  {
      1:string message
  }
  
  
  typedef list&lt;Log&gt; LogsModel
  
  service MessageStorage
  {
      void messageAppended(1:string message),
      void messageRemoved(1:i32 index),
      i32 storageSize(),
      void addMessage(1:string message),
      string getMessage()
  }
  </code></pre>
  
  <p>Server file (not yet finished)</p>
  
  <pre><code>// This autogenerated skeleton file illustrates how to build a server.
  // You should copy it to another filename to avoid overwriting it. 
  
  #include &lt;iostream&gt;
  #include "MessageStorage.h"
  #include "LogViewerServices_types.h"
  #include &lt;thrift/protocol/TBinaryProtocol.h&gt;
  #include &lt;thrift/server/TSimpleServer.h&gt;
  #include &lt;thrift/transport/TServerSocket.h&gt;
  #include &lt;thrift/transport/TBufferTransports.h&gt;
  
  using namespace ::apache::thrift;
  using namespace ::apache::thrift::protocol;
  using namespace ::apache::thrift::transport;
  using namespace ::apache::thrift::server;
  
  using boost::shared_ptr;
  
  class MessageStorageHandler : virtual public MessageStorageIf {
  public:
    LogsModel *logsModel = new LogsModel;
  
    MessageStorageHandler() {
     // Your initialization goes here
    }
  
    void messageAppended(const std::string&amp; message) {
      getMessage(message);
    }
  
    void messageRemoved(const int32_t index) {
        for(int i = 0; i &lt; logsModel-&gt;size(); i++) {
            if(i = index) {
                logsModel[i].erase(logsModel-&gt;begin() + index);
            }
        }
  
    std::cout &lt;&lt; "Item deleted" &lt;&lt; std::endl;
    }
  
    int32_t storageSize() {
        std::cout &lt;&lt; "Rozmiar vectora:\t" &lt;&lt; logsModel-&gt;size();
        return logsModel-&gt;size();
    }
  
    void addMessage(const std::string&amp; message) {
        Log *log = new Log;
        log-&gt;message = message;
  
        logsModel-&gt;push_back(*log);
        std::cout &lt;&lt; "Tresc wiadomosc:\t" &lt;&lt; message &lt;&lt; std::endl;
  
        messageAppended(message);
    }
  
    void getMessage(std::string&amp; _return) {
  
    }
  
  };
  
  int main(int argc, char **argv) {
    int port = 9090;
    shared_ptr&lt;MessageStorageHandler&gt; handler(new MessageStorageHandler());
    shared_ptr&lt;TProcessor&gt; processor(new MessageStorageProcessor(handler));
    shared_ptr&lt;TServerTransport&gt; serverTransport(new TServerSocket(port));
    shared_ptr&lt;TTransportFactory&gt; transportFactory(new TBufferedTransportFactory());
    shared_ptr&lt;TProtocolFactory&gt; protocolFactory(new TBinaryProtocolFactory());
  
    TSimpleServer server(processor, serverTransport, transportFactory, protocolFactory);
    std::cout &lt;&lt; "Server started..." &lt;&lt; std::endl;
    server.serve();
    return 0;
  }
  </code></pre>
  
  <p>And MessageGenerator file</p>
  
  <pre><code>#include "messagegenerator.h"
  #include "ui_messagegenerator.h"
  
  #include "LogViewerServices_types.h"
  #include "MessageStorage.h"
  
  #include &lt;QDebug&gt;
  
  #include &lt;thrift/protocol/TBinaryProtocol.h&gt;
  #include &lt;thrift/transport/TSocket.h&gt;
  #include &lt;thrift/transport/TTransportUtils.h&gt;
  
  using namespace apache::thrift;
  using namespace apache::thrift::protocol;
  using namespace apache::thrift::transport;
  
  MessageGenerator::MessageGenerator(QWidget *parent) :
      QWidget(parent),
      ui(new Ui::MessageGenerator)
  {
      ui-&gt;setupUi(this);
  
      connect(ui-&gt;le_message, &amp;QLineEdit::returnPressed, this, [this]
      {
          if(ui-&gt;le_message-&gt;text().isEmpty())
          {
              qDebug() &lt;&lt; "Nie ma tresci";
              return;
          }
  
          std::string message = (ui-&gt;le_message-&gt;text()).toStdString();
          ui-&gt;le_message-&gt;clear();
  
          boost::shared_ptr&lt;TTransport&gt; socket(new TSocket("localhost", 9090));
          boost::shared_ptr&lt;TTransport&gt; transport(new TBufferedTransport(socket));
          boost::shared_ptr&lt;TProtocol&gt; protocol(new TBinaryProtocol(transport));
  
          try
          {
              MessageStorageClient client(protocol);
              transport-&gt;open();
  
              client.addMessage(message);
          }  
  
          catch(const std::exception &amp;e)
          {
              qCritical() &lt;&lt; "Error" &lt;&lt; e.what();
          }
      });
  }
  
  MessageGenerator::~MessageGenerator()
  {
      delete ui; 
  }
  </code></pre>