Page 8 of 15
Re: hbQT - Post queries in this thread only
Posted: Sat Sep 11, 2010 3:50 pm
by Roberto Lopez
Pritpal,
I'm trying to retrieve elements from a qlist returned by qPrinterinfo.
Code: Select all
oPrinterInfo := qPrinterInfo():New()
oPrinterList := qList():from(oPrinterInfo:AvailablePrinters())
MsgInfo( str( oPrinterList:Size() ) ) // Returns the correct printer count
MsgInfo( oPrinterList:at(1):PrinterName() ) // Gives an error (not exported method: Printername)
The original C++ sample that was the base for the previous code and I'm trying to reproduce:
Code: Select all
QList<QPrinterInfo> printerList = QPrinterInfo::availablePrinters();
QString printers("Printers:\n");
for (int c = 0; c < printerList.size(); ++c) {
printers += printerList[c].printerName();
printers += QLatin1String("\n");
}
Any help on this is welcome.
Thanks in advance.
Re: hbQT - Post queries in this thread only
Posted: Sat Sep 11, 2010 4:08 pm
by Rathinagiri
I think the following code can be used:
Code: Select all
oPrinterInfo := qPrinterInfo():New()
oPrinterList := qList():from(oPrinterInfo:AvailablePrinters())
MsgInfo( str( oPrinterList:Size() ) ) // Returns the correct printer count
For i := 1 to oPrinterList:Size()
MsgInfo( oPrinterList:at(i) )
Next i
I think QList here is a list of strings and not objects!
Re: hbQT - Post queries in this thread only
Posted: Sat Sep 11, 2010 4:17 pm
by Rathinagiri
I am sorry!
Does this work?!
Code: Select all
oPrinterInfo := qPrinterInfo():New()
oPrinterList := qList():from(oPrinterInfo:AvailablePrinters())
MsgInfo( str( oPrinterList:Size() ) ) // Returns the correct printer count
For i := 1 to oPrinterList:Size()
oPrinter := QPrinter():from(oPrinterList:at(i))
MsgInfo( oPrinter:printerName() )
Next i
Re: hbQT - Post queries in this thread only
Posted: Sat Sep 11, 2010 4:18 pm
by Roberto Lopez
rathinagiri wrote:I think the following code can be used:
Code: Select all
oPrinterInfo := qPrinterInfo():New()
oPrinterList := qList():from(oPrinterInfo:AvailablePrinters())
MsgInfo( str( oPrinterList:Size() ) ) // Returns the correct printer count
For i := 1 to oPrinterList:Size()
MsgInfo( oPrinterList:at(i) )
Next i
I think QList here is a list of strings and not objects!
Your code gives an error at the following line:
Error BASE/1081 Argument error: +
Re: hbQT - Post queries in this thread only
Posted: Sat Sep 11, 2010 4:23 pm
by Roberto Lopez
I guess I've found a solution.
oPrinterList:at(i) type is pointer, so I guess that creating a qprinterinfo object from it, could work.
I'll try.
Re: hbQT - Post queries in this thread only
Posted: Sat Sep 11, 2010 4:27 pm
by Rathinagiri
Had my 2nd solution worked?
Re: hbQT - Post queries in this thread only
Posted: Sat Sep 11, 2010 4:27 pm
by Roberto Lopez
Pritpal, Rathinagiri,
I've solved, sorry to disturb you with this:
oPrinterInfo := qPrinterInfo():New()
oPrinterList := qList():from(oPrinterInfo:AvailablePrinters())
For i := 0 to oPrinterList:Size() - 1
qpi := qprinterinfo():from( oPrinterList:at(i) )
MsgInfo( qpi:printername() )
Next i
Re: hbQT - Post queries in this thread only
Posted: Sat Sep 11, 2010 4:30 pm
by Roberto Lopez
Roberto Lopez wrote:I've solved, sorry to disturb you with this:
When we are unsure, we must always check the type returned and when it is a pointer, create the required object for it.
Re: hbQT - Post queries in this thread only
Posted: Sat Sep 11, 2010 5:27 pm
by bedipritpal
Roberto Lopez wrote:
Code: Select all
oPrinterInfo := qPrinterInfo():New()
oPrinterList := qList():from(oPrinterInfo:AvailablePrinters())
For i := 0 to oPrinterList:Size() - 1
qpi := qprinterinfo():from( oPrinterList:at(i) )
MsgInfo( qpi:printername() )
Next i
It does not matter but will be helpful for you to achieve Harbour level formatting quality:
oPrinterList := qList():from(oPrinterInfo:AvailablePrinters())
=>
oPrinterList := QList():from( oPrinterInfo:availablePrinters() )
I mean:
Method call to a class instance must be started with _lower_ case => oPrinterInfo:availablePrinters()
Class constructor must ever be initiated with _upper_ case => QPrinterInfo():from( ... )
Parenthesis must contain a space after opening and before closing brace.
Re: hbQT - Post queries in this thread only
Posted: Sat Sep 11, 2010 7:48 pm
by Roberto Lopez
bedipritpal wrote:
I mean:
Method call to a class instance must be started with _lower_ case => oPrinterInfo:availablePrinters()
Class constructor must ever be initiated with _upper_ case => QPrinterInfo():from( ... )
Parenthesis must contain a space after opening and before closing brace.
Thanks!