Comments (8)
It should close the document. But because of conflict with QWidget::close()
method, I've just renamed it to QPdfWidget::closeDocument()
. It closes the document and resets the view to a default empty one.
from qpdf.
still not closing.it crashes the whole app.
can include the methode in your viewer??
here is my code
`
corepdf::corepdf(QWidget *parent):QWidget(parent)
{
// openPdfFile("/home/shaber/Desktop/p.pdf");
setObjectName("corepdf");
setStyleSheet("QWidget{background-color: #3E3E3E;border: 1px #2A2A2A;}");
}
corepdf::~corepdf()
{
delete PdfWidget;
}
void corepdf::eclose()
{
QPdfWidget *cpdf = this->findChild<QPdfWidget*>("QPdfWidget");
cpdf->closeDocument();
}
void corepdf::openPdfFile(const QString path)
{
workFilePath = path;
QVBoxLayout * mainLayout = new QVBoxLayout();
PdfWidget = new QPdfWidget();
connect(PdfWidget, &QPdfWidget::initialized, [this,path]() {
PdfWidget->setToolbarVisible(false);
QFile f(path);
if (f.open(QIODevice::ReadOnly)) {
QByteArray data = f.readAll();
PdfWidget->loadData(data);
f.close();
}
});
cShot = new QPushButton("close");
connect(cShot,SIGNAL(clicked()),this,SLOT(eclose()));
mainLayout->setContentsMargins(0,0,0,0);
mainLayout->addWidget(PdfWidget);
mainLayout->addWidget(cShot);
setLayout(mainLayout);
}
`
`
//header
class corepdf : public QWidget
{
Q_OBJECT
public:
corepdf(QWidget *parent = 0);
~corepdf();
void openPdfFile(const QString path);
QString workFilePath;
protected:
void closeEvent(QCloseEvent *event);
public slots:
void eclose();
private:
QPushButton * cShot;
QPdfWidget *PdfWidget;
};
`
from qpdf.
Are you sure the following code of yours
QPdfWidget *cpdf = this->findChild<QPdfWidget*>("QPdfWidget");
does not return null? Because you never assign "QPdfWidget" name to your widget.
Try adding the following when creating the widget:
QVBoxLayout * mainLayout = new QVBoxLayout();
PdfWidget = new QPdfWidget(); // BTW, do you really want to create a new widget every time you open a file?
PdfWidget->setObjectName("QPdfWidget"); // Without the name assignment findWidget() won't find anything
Or better create your PdfWidget in constructor and access it via member variable of your corepdf
class.
from qpdf.
i can't add qpdfwidget in constructor .
there is some ui problem.
i added the object name .but still closing qpdfwidget is crashing the whole app.
i don't know how to check ,if the widget is found or not.
from qpdf.
Well, you check it against nullptr
:
void corepdf::eclose()
{
QPdfWidget *cpdf = this->findChild<QPdfWidget*>("QPdfWidget");
if (cpdf != nullptr) {
cpdf->closeDocument();
} else {
qWarning() << "Not found!";
}
}
from qpdf.
yes . widget is not found.
from qpdf.
i found the solution .
QPdfWidget *cpdf = qobject_cast<QPdfWidget*>(this->children().at(1));
from qpdf.
This is not a good solution, which will break when you start changing the layout or add more children QObjects to your corepdf
. I would recommend to capture cpdf
pointer as a class member field instead.
from qpdf.
Related Issues (20)
- [Feature Request] add some feature HOT 2
- include linux support
- Update pdf.js HOT 2
- not getting the document properties and destination
- [Feature Request] add this functions HOT 1
- Request for as a library
- Error displaying PDF - White font HOT 3
- Release build does not work. HOT 5
- Qtreeview for bookmark HOT 2
- [Question]: What pdfDocumentDestinations to do? HOT 1
- Reproduce Video which is inside a PDF file HOT 2
- [Feature request] add filler function HOT 2
- FATAL:ipc_mojo_bootstrap.cc(729)] Check failed: message->data_num_bytes() <= Channel::kMaximumMessageSize HOT 11
- After set #define QPDF_WIDGET_USE_CORS:URL scheme must be "http" or "https" for CORS request.
- QWidget: Must construct a QApplication before a QWidget HOT 3
- Error on using qpdf.lib on vs 2019 HOT 4
- How to Deploy ? HOT 2
- Not able to build this project on Ubuntu 20.04 HOT 2
- js: #document_properties_keywords is undefined. HOT 1
- please update pdf.js to 4.x or 3.x HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from qpdf.