I am not quite sure what you mean. I am a beginner myself but I wonder, can you first get the text from LineEdit and then send it to the printer function? Basically dividing the process into smaller steps to diagnose where the problem occurs.
#include <QDebug>
void MainWindow::on_actionPrint_triggered()
{
// actionPrint triggered
qDebug() << "actionPrint triggered."
// instanciate new printer
qDebug() << "Printer instanciated."
// Set name
printer.setPrinterName("Desired printer name");
qDebug() << "Printer name set: " + printer.name;
// Instanciate new QPrintDialog
// Dialog
if(dialog.
exec() == QDialog::Rejected) {
qDebug() << "QDialog rejected!";
return;
}
// get text from LineEdit
QString toPrint
= ui
->lineEdit
->text
().
toString();
qDebug() << "LineEdit text retreived:\n" + toPrint;
// Print text from LineEdit
toPrint->print(&printer);
qDebug() << "Text print function called.";
#include <QDebug>
void MainWindow::on_actionPrint_triggered()
{
// actionPrint triggered
qDebug() << "actionPrint triggered."
// instanciate new printer
QPrinter printer;
qDebug() << "Printer instanciated."
// Set name
printer.setPrinterName("Desired printer name");
qDebug() << "Printer name set: " + printer.name;
// Instanciate new QPrintDialog
QPrintDialog dialog(&printer,this);
// Dialog
if(dialog.exec() == QDialog::Rejected)
{
qDebug() << "QDialog rejected!";
return;
}
// get text from LineEdit
QString toPrint = ui->lineEdit->text().toString();
qDebug() << "LineEdit text retreived:\n" + toPrint;
// Print text from LineEdit
toPrint->print(&printer);
qDebug() << "Text print function called.";
To copy to clipboard, switch view to plain text mode
Maybe "QString toPrint" isn't what you should end up using in the end, you might change it to QDocument or something else, I amnot quite sure really since I have never worked with those classes. I just thought that having the qDebug telling you what is going on might help you narrow down your your problem occurs.
Bookmarks