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. Serialize QPixmap in console app
Forum Updated to NodeBB v4.3 + New Features

Serialize QPixmap in console app

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 2.5k 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.
  • M Offline
    M Offline
    Misty River
    wrote on last edited by
    #1

    Hello,

    I am trying to serialize a QPixmap between a server and a client app. The server is a console app and the client a gui one. The server always crash when I serialize the pixmap while the client stay alive.. so I'm guessing it has something to do with being a console app.. do I need to enable something in the project file ? I have already added += gui to use QPixmap ...

    raven-worxR 1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      Can you show us your code?

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      M 1 Reply Last reply
      0
      • VRoninV VRonin

        Can you show us your code?

        M Offline
        M Offline
        Misty River
        wrote on last edited by
        #3

        @VRonin I'm afraid it is way way way to big to post

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          Just the part where you serialise

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          M 1 Reply Last reply
          0
          • VRoninV VRonin

            Just the part where you serialise

            M Offline
            M Offline
            Misty River
            wrote on last edited by
            #5

            @VRonin

            void Server::sendProfilePicture(QPixmap pProfilePicture, const QString & pPseudo)
            {
                QByteArray paquet;
                QDataStream out(&paquet, QIODevice::WriteOnly);
                out << (quint64) 0;
            
                Message message(PROFILEPICTURE);
                message.setOption(0);
                message.setProfilePicture(pProfilePicture);
            
                out << message;
                out.device()->seek(0);
                out << (quint64) (paquet.size() - sizeof(quint64));
                if (socketFromPseudo(pPseudo) != NULL) {
                    socketFromPseudo(pPseudo)->write(paquet);
                }
            }
            

            This will probably be Chinese without the rest of the code but this is where the crash happens...

            1 Reply Last reply
            0
            • M Misty River

              Hello,

              I am trying to serialize a QPixmap between a server and a client app. The server is a console app and the client a gui one. The server always crash when I serialize the pixmap while the client stay alive.. so I'm guessing it has something to do with being a console app.. do I need to enable something in the project file ? I have already added += gui to use QPixmap ...

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              @Misty-River
              you need to create a QGuiApplication (instead of a QCoreApplication) in your server application.

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              1
              • Hamed.MasafiH Offline
                Hamed.MasafiH Offline
                Hamed.Masafi
                wrote on last edited by Hamed.Masafi
                #7

                QPixmap need to create in gui thread. I have had same problem with chat server application. You need to use QImage.
                From qdoc:

                Qt provides four classes for handling image data: QImage, QPixmap, QBitmap and QPicture. QImage is designed and optimized for I/O, and for direct pixel access and manipulation, while QPixmap is designed and optimized for showing images on screen. QBitmap is only a convenience class that inherits QPixmap, ensuring a depth of 1. Finally, the QPicture class is a paint device that records and replays QPainter commands.

                So using QImage in server app is better than QPixmap.

                Remote object sharing (OO RPC)
                http://forum.qt.io/topic/60680/remote-object-sharing-oo-rpc-solved

                Advanced, Powerful and easy to use ORM for Qt5
                https://forum.qt.io/topic/67417/advanced-powerful-and-easy-to-use-orm-for-qt5

                M 1 Reply Last reply
                3
                • Hamed.MasafiH Hamed.Masafi

                  QPixmap need to create in gui thread. I have had same problem with chat server application. You need to use QImage.
                  From qdoc:

                  Qt provides four classes for handling image data: QImage, QPixmap, QBitmap and QPicture. QImage is designed and optimized for I/O, and for direct pixel access and manipulation, while QPixmap is designed and optimized for showing images on screen. QBitmap is only a convenience class that inherits QPixmap, ensuring a depth of 1. Finally, the QPicture class is a paint device that records and replays QPainter commands.

                  So using QImage in server app is better than QPixmap.

                  M Offline
                  M Offline
                  Misty River
                  wrote on last edited by
                  #8

                  @Hamed.Masafi Ok thank you. I have switched to QImage and it stopped crashing.

                  1 Reply Last reply
                  0

                  • Login

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