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. QPdfView: No such file or directory
QtWS25 Last Chance

QPdfView: No such file or directory

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 5 Posters 698 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 Offline
    J Offline
    Jayakrishna
    wrote on 20 Jul 2024, 14:59 last edited by
    #1

    Hello everyone, I am try to use QPdfView it is showing fatal error can anyone resolve it
    my .pro file

    QT       += core gui bluetooth pdf
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    CONFIG += c++17
    
    # You can make your code fail to compile if it uses deprecated APIs.
    # In order to do so, uncomment the following line.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    
    SOURCES += \
        main.cpp \
        mainwindow.cpp
    
    HEADERS += \
        mainwindow.h
    
    FORMS += \
        mainwindow.ui
    
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    

    mainwindow.h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    #include <QPdfDocument>
    #include <QPdfView>
    #include <QVBoxLayout>
    #include <QPushButton>
    #include <QFileDialog>
    
    QT_BEGIN_NAMESPACE
    namespace Ui { class MainWindow; }
    QT_END_NAMESPACE
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        MainWindow(QWidget *parent = nullptr);
        ~MainWindow();
    
    private slots:
        void openPDF();
    
    private:
        Ui::MainWindow *ui;
        QPdfDocument *pdfDocument;
        QPdfView *pdfView;
        QVBoxLayout *layout;
        QPushButton *openButton;
    };
    
    #endif // MAINWINDOW_H
    

    D:\QTProjects\Previwer\Pdfviewer\mainwindow.h:6: error: QPdfView: No such file or directory
    In file included from debug\moc_mainwindow.cpp:9:
    debug../../../mainwindow.h:6:10: fatal error: QPdfView: No such file or directory
    6 | #include <QPdfView>
    | ^~~~~~~~~~

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 20 Jul 2024, 15:08 last edited by
      #2

      What Qt version do you use?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jayakrishna
        wrote on 20 Jul 2024, 16:12 last edited by
        #3

        Qt 6.7.2

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 20 Jul 2024, 16:20 last edited by Christian Ehrlicher
          #4

          And did you install the pdf module (don't know if this needed) and do you find QPdfView in the Qt includes folder?

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Axel Spoerl
            Moderators
            wrote on 21 Jul 2024, 04:15 last edited by
            #5

            For CMake you need to link Qt::PdfWidgets.
            Not entirely sure for qmake, but it’s probably QT+=pdfwidgets

            Software Engineer
            The Qt Company, Oslo

            J J 2 Replies Last reply 21 Jul 2024, 06:49
            2
            • A Axel Spoerl
              21 Jul 2024, 04:15

              For CMake you need to link Qt::PdfWidgets.
              Not entirely sure for qmake, but it’s probably QT+=pdfwidgets

              J Online
              J Online
              JonB
              wrote on 21 Jul 2024, 06:49 last edited by JonB
              #6

              @Axel-Spoerl said in QPdfView: No such file or directory:

              Not entirely sure for qmake, but it’s probably QT+=pdfwidgets

              Yes, the Qt5.15 example at https://doc.qt.io/qt-5/qtpdf-pdfviewer-pdfviewer-pro.html shows this and is what @Jayakrishna should follow for qmake. An example apparently for Qt6 at https://code.qt.io/cgit/qt/qtwebengine.git/tree/examples/pdfwidgets/pdfviewer?h=6.7 shows same, and has both a .pro and a CMakeLists.txt.

              I don't use Qt6, but given that the OP is at Qt 6.7.2 shouldn't they be using cmake rather than qmake/.pro file?

              S 1 Reply Last reply 21 Jul 2024, 07:16
              0
              • J JonB
                21 Jul 2024, 06:49

                @Axel-Spoerl said in QPdfView: No such file or directory:

                Not entirely sure for qmake, but it’s probably QT+=pdfwidgets

                Yes, the Qt5.15 example at https://doc.qt.io/qt-5/qtpdf-pdfviewer-pdfviewer-pro.html shows this and is what @Jayakrishna should follow for qmake. An example apparently for Qt6 at https://code.qt.io/cgit/qt/qtwebengine.git/tree/examples/pdfwidgets/pdfviewer?h=6.7 shows same, and has both a .pro and a CMakeLists.txt.

                I don't use Qt6, but given that the OP is at Qt 6.7.2 shouldn't they be using cmake rather than qmake/.pro file?

                S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 21 Jul 2024, 07:16 last edited by
                #7

                @JonB cmake is indeed recommended for new projects. qmake is in maintenance mode and won't receive new features.

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

                J 1 Reply Last reply 21 Jul 2024, 07:25
                1
                • S SGaist
                  21 Jul 2024, 07:16

                  @JonB cmake is indeed recommended for new projects. qmake is in maintenance mode and won't receive new features.

                  J Online
                  J Online
                  JonB
                  wrote on 21 Jul 2024, 07:25 last edited by
                  #8

                  @SGaist Yes, it was a "rhetorical" question ;-)

                  1 Reply Last reply
                  0
                  • A Axel Spoerl
                    21 Jul 2024, 04:15

                    For CMake you need to link Qt::PdfWidgets.
                    Not entirely sure for qmake, but it’s probably QT+=pdfwidgets

                    J Offline
                    J Offline
                    Jayakrishna
                    wrote on 22 Jul 2024, 09:02 last edited by
                    #9

                    @Axel-Spoerl Thanks, finally my code is working

                    1 Reply Last reply
                    0
                    • J Jayakrishna has marked this topic as solved on 22 Jul 2024, 09:05

                    1/9

                    20 Jul 2024, 14:59

                    • Login

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