Results 1 to 2 of 2

Thread: Pass string to print slot (QPrintPreviewDialog)

  1. #1
    Join Date
    Oct 2014
    Posts
    5
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Pass string to print slot (QPrintPreviewDialog)

    Hi

    I have 2 qplaintextedit with 2 buttons. Each button will pass the text from one qplaintextedit to a string x and call the function printreport and the then print (thats the idea at least)
    I'm trying to implement a QPreviewDialog like this:

    Qt Code:
    1. void::mainwindow::printreport(QString x)
    2. {
    3. QPrinter printer;
    4. printer.setPageSize(QPrinter::A4);
    5. printer.setOrientation(QPrinter::Portrait);
    6. printer.setPageMargins (10,10,10,10,QPrinter::Millimeter);
    7.  
    8. QPrintPreviewDialog preview(&printer);
    9.  
    10. connect(&preview, SIGNAL(paintRequested(QPrinter *)),this, SLOT(printpage(QPrinter*, QString x)));
    11. preview.showMaximized();
    12. preview.exec();
    13.  
    14. }
    15.  
    16. void mainwindow::printpage(QPrinter *printer, QString x)
    17. {
    18. QPainter painter(printer);
    19.  
    20. QRect reccomum(0,0,720,30);
    21.  
    22. painter.drawText(100, 100, "Hello World! 123");
    23. painter.drawText(reccomum,Qt::AlignLeft,x);
    24. }
    To copy to clipboard, switch view to plain text mode 
    This doesn't work. The printpreview dialog shows a gray area. I get this error message:
    QObject::connect: No such slot mainwindow:: printpage(QPrinter*, QString x) in ..\Receitas\mainwindow.cpp:432
    QObject::connect: (receiver name: 'mainwindow')

    When i delete QString x both from void mainwindow:: printpage and from the signal:slot (that is: leaving only SLOT(print(QPrinter*)) the page is created, but without the text from the qplaintextedit.

    My question is: how can i implement this printpage slot passing the string x?

    Thanks in advance.
    Last edited by Rafaelpsmed; 11th February 2015 at 01:15. Reason: wrong typing

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Pass string to print slot (QPrintPreviewDialog)

    A slot can never have more arguments than the signal it is connected to.
    How would the computer know at the point of the emit which value to pass?

    Couple of options:
    You can store the string in a member of mainwindow.
    You can store the string as a dynamic property on the QPrinter.
    You could delegate printing to an instance of a specialized class that has the string to print as its member.

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    Rafaelpsmed (12th February 2015)

Similar Threads

  1. Pass a float value to a string
    By alitoh in forum Newbie
    Replies: 3
    Last Post: 11th April 2011, 17:38
  2. how to print string??
    By pratik in forum Qt Programming
    Replies: 7
    Last Post: 25th December 2010, 16:38
  3. Replies: 13
    Last Post: 30th November 2010, 12:47
  4. Replies: 4
    Last Post: 21st June 2009, 18:06
  5. signal slot conection using a string, not a SLOT
    By rianquinn in forum Qt Programming
    Replies: 6
    Last Post: 5th February 2006, 18:52

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.