QPdfView: No such file or directory
-
Hello everyone, I am try to use QPdfView it is showing fatal error can anyone resolve it
my .pro fileQT += 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>
| ^~~~~~~~~~ -
What Qt version do you use?
-
Qt 6.7.2
-
And did you install the pdf module (don't know if this needed) and do you find QPdfView in the Qt includes folder?
-
For CMake you need to link Qt::PdfWidgets.
Not entirely sure for qmake, but it’s probably QT+=pdfwidgets -
For CMake you need to link Qt::PdfWidgets.
Not entirely sure for qmake, but it’s probably QT+=pdfwidgets@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 aCMakeLists.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?
-
@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 aCMakeLists.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?
-
@JonB cmake is indeed recommended for new projects. qmake is in maintenance mode and won't receive new features.
-
For CMake you need to link Qt::PdfWidgets.
Not entirely sure for qmake, but it’s probably QT+=pdfwidgets@Axel-Spoerl Thanks, finally my code is working
-