hbQT - Post queries in this thread only

Moderator: Rathinagiri

User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: hbQT - Post queries in this thread only

Post 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.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: hbQT - Post queries in this thread only

Post 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!
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: hbQT - Post queries in this thread only

Post 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
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: hbQT - Post queries in this thread only

Post 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:

Code: Select all

  MsgInfo( oPrinterList:at(i) )  
Error BASE/1081 Argument error: +
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: hbQT - Post queries in this thread only

Post 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.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: hbQT - Post queries in this thread only

Post by Rathinagiri »

Had my 2nd solution worked?
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: hbQT - Post queries in this thread only

Post 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
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: hbQT - Post queries in this thread only

Post 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.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
bedipritpal
Posts: 122
Joined: Thu Sep 02, 2010 10:47 pm

Re: hbQT - Post queries in this thread only

Post 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.
enjoy hbIDEing... Pritpal Bedi
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: hbQT - Post queries in this thread only

Post 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!
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
Post Reply