Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QImageWriter not working - QML
Qt 6.11 is out! See what's new in the release blog

QImageWriter not working - QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
7 Posts 2 Posters 639 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.
  • D Offline
    D Offline
    Dillon
    wrote on last edited by
    #1

    I've been trying to use QImageWriter to add metadata to a tiff file but when I I run the code it gives me the error that QImageWriter is not defined. I have added the necessary code to the CMAKE and main.cpp header but it still seems to be giving me an error. This is being written in QML. Any help or guidance in an alternative way to write metadata to tiff would be greatly appreciated. Thanks!

    B 1 Reply Last reply
    0
    • D Dillon

      I've been trying to use QImageWriter to add metadata to a tiff file but when I I run the code it gives me the error that QImageWriter is not defined. I have added the necessary code to the CMAKE and main.cpp header but it still seems to be giving me an error. This is being written in QML. Any help or guidance in an alternative way to write metadata to tiff would be greatly appreciated. Thanks!

      B Offline
      B Offline
      Bob64
      wrote on last edited by
      #2

      @Dillon can you give more details of how you are trying to do this. Is it when you are trying to call something from QML that you are getting this error? QImageWriter isn't directly accessible from QML so how are you exposing its functionality to the QML layer (if indeed that is what you are trying to do)?

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Dillon
        wrote on last edited by
        #3

        Ahhh, yes. That may be the issue then. I found an example (modified below)

                        var writer = new QImageWriter()
                        writer.setFormat("tiff")
                        writer.setText("Creator", "Dillon")
                        writer.setText("Geog Ellipsoid", "GRS 1980")
                        writer.write(image)
        

        I am not too familiar with how to use the functions from the C++ side of things.

        Basically, I have an image that I am grabbing from the view and then I want to add metadata to the image before saving the file.
        I have already setup the file dialog save function and that is working well but now I need to add the metadata prior to saving.

        B 1 Reply Last reply
        0
        • D Dillon

          Ahhh, yes. That may be the issue then. I found an example (modified below)

                          var writer = new QImageWriter()
                          writer.setFormat("tiff")
                          writer.setText("Creator", "Dillon")
                          writer.setText("Geog Ellipsoid", "GRS 1980")
                          writer.write(image)
          

          I am not too familiar with how to use the functions from the C++ side of things.

          Basically, I have an image that I am grabbing from the view and then I want to add metadata to the image before saving the file.
          I have already setup the file dialog save function and that is working well but now I need to add the metadata prior to saving.

          B Offline
          B Offline
          Bob64
          wrote on last edited by Bob64
          #4

          @Dillon exactly how to go about it will depend on your requirements. I'm on my phone so can't write code easily, but the docs explain the different methods available: https://doc.qt.io/qt-5/qtqml-cppintegration-overview.html

          Edit: if all you need to do is to call that code you listed, as a function, I would probably use the approach documented here:

          https://doc.qt.io/qt-5/qtqml-cppintegration-contextproperties.html

          Look at the "Setting an Object as a Context Property" section. Basically, it involves creating a simple class that has your function as a method. You then register an instance of your class as a "context property".

          1 Reply Last reply
          0
          • D Offline
            D Offline
            Dillon
            wrote on last edited by
            #5

            @Bob64 Thank you for the direction. I tried utilizing that but I am getting an error during with CMAKE referencing something with the obj. I may be doing this completely wrong but I have not had any luck with it.

            Also, Just from looking over some of that feature it seems as though I will only be able to write predefined text from the C++ class? The function will need to change the data depending on certain parameters.

            Again, I may be completely off on understanding this. Thanks for your help so far!

            1 Reply Last reply
            0
            • D Offline
              D Offline
              Dillon
              wrote on last edited by
              #6

              @Bob64 Just an update, the error I am getting is stating that there is no file or directory for pthreads when I add the class to the main.cpp file. It will not compile. I have tried changing the compiler to MinGW and the pthread issue disappears but then I get an error command line '-' and the application will not load. I am at a loss as what to do next.

              1 Reply Last reply
              0
              • D Offline
                D Offline
                Dillon
                wrote on last edited by
                #7

                Minor update, Narrowed down the issue to Q_OBJECT in the class being a problem during compiling. Looking into other options for exposing the function properly

                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