Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Incompatible pointer type when referencing the method.

Incompatible pointer type when referencing the method.

Scheduled Pinned Locked Moved Solved C++ Gurus
pdfiumreference error
14 Posts 4 Posters 2.6k 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.
  • J J.Hilk
    11 Nov 2021, 10:51

    @artwaw

    I think you could simply use a lambda stored in an auto and capture a reference to your QDataStream and/or class instance in general.

    not the cleanest solution, but should work.

    A Offline
    A Offline
    artwaw
    wrote on 11 Nov 2021, 11:14 last edited by
    #5

    @J-Hilk Thank you but I don't know how to do that. I use lambdas with connect when needed, but my c++ skill is not enough.

    I could get away with making QDataStream a public member of QMainWindow but I feel dirty just thinking of it.

    For more information please re-read.

    Kind Regards,
    Artur

    J 1 Reply Last reply 11 Nov 2021, 11:20
    0
    • A artwaw
      11 Nov 2021, 11:14

      @J-Hilk Thank you but I don't know how to do that. I use lambdas with connect when needed, but my c++ skill is not enough.

      I could get away with making QDataStream a public member of QMainWindow but I feel dirty just thinking of it.

      J Offline
      J Offline
      J.Hilk
      Moderators
      wrote on 11 Nov 2021, 11:20 last edited by
      #6

      @artwaw said in Incompatible pointer type when referencing the method.:

      Thank you but I don't know how to do that. I use lambdas with connect when needed, but my c++ skill is not enough.

      this is untested:

      FPDF_FILEWRITE writer;
          writer.version = 1; 
          auto myFunction = [this](FPDF_FILEWRITE* pThis, const void* pData, unsigned long size)->int {
              Q_UNUSED(pThis)
              return writerStream.writeRawData(static_cast<const char*>(pData), size);
      }
          writer.WriteBlock = &myFunction;
          bool result = FPDF_SaveAsCopy(document, &writer,FPDF_INCREMENTAL);
      

      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      A 2 Replies Last reply 11 Nov 2021, 11:22
      1
      • J J.Hilk
        11 Nov 2021, 11:20

        @artwaw said in Incompatible pointer type when referencing the method.:

        Thank you but I don't know how to do that. I use lambdas with connect when needed, but my c++ skill is not enough.

        this is untested:

        FPDF_FILEWRITE writer;
            writer.version = 1; 
            auto myFunction = [this](FPDF_FILEWRITE* pThis, const void* pData, unsigned long size)->int {
                Q_UNUSED(pThis)
                return writerStream.writeRawData(static_cast<const char*>(pData), size);
        }
            writer.WriteBlock = &myFunction;
            bool result = FPDF_SaveAsCopy(document, &writer,FPDF_INCREMENTAL);
        
        A Offline
        A Offline
        artwaw
        wrote on 11 Nov 2021, 11:22 last edited by
        #7

        @J-Hilk Thank you, will test.

        For more information please re-read.

        Kind Regards,
        Artur

        1 Reply Last reply
        0
        • J J.Hilk
          11 Nov 2021, 11:20

          @artwaw said in Incompatible pointer type when referencing the method.:

          Thank you but I don't know how to do that. I use lambdas with connect when needed, but my c++ skill is not enough.

          this is untested:

          FPDF_FILEWRITE writer;
              writer.version = 1; 
              auto myFunction = [this](FPDF_FILEWRITE* pThis, const void* pData, unsigned long size)->int {
                  Q_UNUSED(pThis)
                  return writerStream.writeRawData(static_cast<const char*>(pData), size);
          }
              writer.WriteBlock = &myFunction;
              bool result = FPDF_SaveAsCopy(document, &writer,FPDF_INCREMENTAL);
          
          A Offline
          A Offline
          artwaw
          wrote on 11 Nov 2021, 11:27 last edited by
          #8

          @J-Hilk
          PdfWizard.cpp:358:25: error: incompatible pointer types assigning to 'int (*)(struct FPDF_FILEWRITE_ *, const void *, unsigned long)' from '(lambda at PdfWizard.cpp:350:24) *'

          For more information please re-read.

          Kind Regards,
          Artur

          J 1 Reply Last reply 11 Nov 2021, 11:44
          0
          • A artwaw
            11 Nov 2021, 10:45

            @jsulm but how?
            Sure, I can move that callback outside the class. That also means I'd need to somehow move the QDataStream outside... I am not sure if I know how to safely and correctly design that.
            PdfWizard is of QMainWindow, so everything is in it.

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 11 Nov 2021, 11:36 last edited by
            #9

            @artwaw said in Incompatible pointer type when referencing the method.:

            but how?

            Well, you need to get access to the instance. One way is to make the class a singleton.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            A 1 Reply Last reply 11 Nov 2021, 11:42
            1
            • J jsulm
              11 Nov 2021, 11:36

              @artwaw said in Incompatible pointer type when referencing the method.:

              but how?

              Well, you need to get access to the instance. One way is to make the class a singleton.

              A Offline
              A Offline
              artwaw
              wrote on 11 Nov 2021, 11:42 last edited by
              #10

              @jsulm said in Incompatible pointer type when referencing the method.:

              make the class a singleton

              I went here https://www.oreilly.com/library/view/c-cookbook/0596007612/ch08s10.html

              This is doable, I think, but at this point I am coming to the conclusion that it would be better to redesign my approach by wrapping all interactions with PDFium into a separate class and only expose methods that do stuff I need.

              There is so much I don't know how to do yet...

              For more information please re-read.

              Kind Regards,
              Artur

              1 Reply Last reply
              0
              • A artwaw
                11 Nov 2021, 11:27

                @J-Hilk
                PdfWizard.cpp:358:25: error: incompatible pointer types assigning to 'int (*)(struct FPDF_FILEWRITE_ *, const void *, unsigned long)' from '(lambda at PdfWizard.cpp:350:24) *'

                J Offline
                J Offline
                J.Hilk
                Moderators
                wrote on 11 Nov 2021, 11:44 last edited by
                #11

                @artwaw oops, my bad, a lambda can only be converted to a function pointer if it does not capture

                The closure type for a lambda-expression with no lambda-capture has a public non-virtual non-explicit const conversion function to pointer to function having the same parameter and return types as the closure type’s function call operator. The value returned by this conversion function shall be the address of a function that, when invoked, has the same effect as invoking the closure type’s function call operator.

                Reference link


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                1 Reply Last reply
                1
                • A Offline
                  A Offline
                  artwaw
                  wrote on 11 Nov 2021, 14:05 last edited by
                  #12

                  I managed to construct a singleton class to handle the I/O and so it works. Thank you all for the input, it is always great to learn from you!

                  For more information please re-read.

                  Kind Regards,
                  Artur

                  1 Reply Last reply
                  1
                  • M Offline
                    M Offline
                    mpergand
                    wrote on 11 Nov 2021, 20:04 last edited by mpergand 11 Dec 2021, 20:33
                    #13

                    I know nothing about Poppler but for defining a C callback method in C++, this method need to be static.
                    See this post

                    A 1 Reply Last reply 11 Nov 2021, 20:12
                    0
                    • M mpergand
                      11 Nov 2021, 20:04

                      I know nothing about Poppler but for defining a C callback method in C++, this method need to be static.
                      See this post

                      A Offline
                      A Offline
                      artwaw
                      wrote on 11 Nov 2021, 20:12 last edited by
                      #14

                      @mpergand thank you but:

                      • I stated previously that I work with PDFium this time, as Poppler doesn't offer edits;
                      • I managed to work around without using static method: maybe not the nicest solution around but works.

                      At any rate I made a note of your comment in case I need to revisit this godawful file format known as PDF in the future.

                      For more information please re-read.

                      Kind Regards,
                      Artur

                      1 Reply Last reply
                      0

                      14/14

                      11 Nov 2021, 20:12

                      • Login

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