Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 3

Qt-interest Archive, December 2007
Why no QSqlQuery::value(QString&) method ?

Pages: Prev | 1 | 2 | Next

Message 1 in thread

Is there a reason for the lack of such a method in QSqlQuery ?
I note that it exists in QSqlRecord and it would seem to be
an obvious candidate for QSqlQuery too.

For the time being I cooked one up like this:

class SqlQuery : public QSqlQuery
{
    public:
        SqlQuery(const QSqlQuery &base) : QSqlQuery(base) { };

        QVariant column_value(QString column)
        {
            QSqlRecord rec = record();
            int i = rec.indexOf(column);
            if (i == -1)
            {
                throw std::runtime_error(qPrintable(column + " does not
exist"));
            }
            return value(i);
        };
};


Is this likely to break in ways I haven't thought of ?
(and if so, are such ways the reason for the lack of
such a native method ?)

-- 
 [ signature omitted ] 

Message 2 in thread

Stephen Collyer wrote:

> Is there a reason for the lack of such a method in QSqlQuery ?
> I note that it exists in QSqlRecord and it would seem to be
> an obvious candidate for QSqlQuery too.

My guess is that it was left out because it's just a convenience 
function that isn't really required, that the index based lookup is 
faster, and that no-one asked for it.

Subclassing QSqlQuery is a bit of overkill. You can simply use 
QSqlRecord::value(QString&) instead: query.record().value(fieldName).

... but if you prefer to see it in the QSqlQuery API you can submit a 
feature suggestion of course :-)


--
 [ signature omitted ] 

Message 3 in thread

On torsdag den 13. December 2007, Anders Larsen wrote:
> Stephen Collyer wrote:
> > Is there a reason for the lack of such a method in QSqlQuery ?
> > I note that it exists in QSqlRecord and it would seem to be
> > an obvious candidate for QSqlQuery too.
>
> My guess is that it was left out because it's just a convenience
> function that isn't really required, that the index based lookup is
> faster, and that no-one asked for it.
>
> Subclassing QSqlQuery is a bit of overkill. You can simply use
> QSqlRecord::value(QString&) instead: query.record().value(fieldName).
>
> ... but if you prefer to see it in the QSqlQuery API you can submit a
> feature suggestion of course :-)

I bet you trolls would reject such a feature. You wouldn't add a method 
that "improve" this:

query.record().value(fieldName);

to this:

query.value(fieldName)

Just imagine the explosion in methods we would have to consider, if this was 
The Way of the Trolls (TM).

Adding convenience functions is not without cost. It makes the interface 
larger, which makes it harder for everyone to find the methods they need, and 
there is a cost in code size on runtime.

I for one hail our troll overlords. (*)

Bo.

(*) Quote (well, almost) Kent Brockmann.

-- 
 [ signature omitted ] 

Message 4 in thread

Bo Thorsen wrote:

> I bet you trolls would reject such a feature. You wouldn't add a method 
> that "improve" this:
> 
> query.record().value(fieldName);
> 
> to this:
> 
> query.value(fieldName)
> 
> Just imagine the explosion in methods we would have to consider, if this was 
> The Way of the Trolls (TM).
> 
> Adding convenience functions is not without cost. It makes the interface 
> larger, which makes it harder for everyone to find the methods they need, and 
> there is a cost in code size on runtime.
> 
> I for one hail our troll overlords. (*)

Do they have irony in Denmark ?

But on vaguely serious note, Qt seems to be full of convenience
functions (in fact, the whole thing is one big "convenience function",
one could argue), so I don't think one more, wafer-thin, convenience
function will hurt.

-- 
 [ signature omitted ] 

Message 5 in thread

On Dec 13, 2007, at 3:51 AM, Bo Thorsen wrote:
> [...snip...]
>
> Just imagine the explosion in methods we would have to consider, if  
> this was
> The Way of the Trolls (TM).
>
> Adding convenience functions is not without cost. It makes the  
> interface
> larger, which makes it harder for everyone to find the methods they  
> need,

I have to respectfully disagree with you on this point at least,  
although your other points stand. I just recently started using Qt  
(about 4 or 5 months ago, I think) and I went through an incredible  
amount of frustration trying to figure out how to do exactly this- get  
the value of a specific field from a QSqlQuery. The documentation  
shows an example of using the QSqlQuery::record().indexOf(fieldname)  
function in conjuction with a QSqlQuery::value(fieldNo) call to get  
the value - arguably the more efficient way to loop through a large  
number of records (as index-based lookups are fast), but to my mind  
overly complicated for just pulling a single value. It took me quite a  
while to track down the fact that the record returned by the record  
command has a value function I could use to get the desired result in  
a "single" call.

This is just one example of many that I have run into in trying to  
learn Qt where there is a function I need, but the closest thing I can  
find takes as an argument some piece of non-obvious data which I have  
to use other functions to find, ad infinitum. This is in spite of  
trying to do something that I would think would be fairly easy, such  
as the above example - see my messages to this list from early October  
Re: Efficient data retrieval. Having such convenience functions  would  
make it easier to find the methods I needed, not harder, even though  
the total number of available methods would be increased.

-----------------------------------------------
Israel Brewster
Computer Support Technician
Frontier Flying Service Inc.
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7250 x293
-----------------------------------------------

> and
> there is a cost in code size on runtime.
>
>
> I for one hail our troll overlords. (*)
>
> Bo.
>
> (*) Quote (well, almost) Kent Brockmann.
>
> -- 
>
> Thorsen Consulting ApS - Qt consulting services
> http://www.thorsen-consulting.dk
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx  
> with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/

--
 [ signature omitted ] 

Message 6 in thread

On Thursday 13 December 2007 18:22:41 Israel Brewster wrote:
> On Dec 13, 2007, at 3:51 AM, Bo Thorsen wrote:
<SNIP/>
> This is just one example of many that I have run into in trying to
> learn Qt where there is a function I need, but the closest thing I can
> find takes as an argument some piece of non-obvious data which I have
> to use other functions to find, ad infinitum. This is in spite of
> trying to do something that I would think would be fairly easy, such
> as the above example - see my messages to this list from early October
> Re: Efficient data retrieval. Having such convenience functions  would
> make it easier to find the methods I needed, not harder, even though
> the total number of available methods would be increased.
>
This is straight from the top part of the documentation:
==> To convert a field name into an index, use record().indexOf(),  <==
or example:
     QSqlQuery query("SELECT * FROM artist");
     int fieldNo = query.record().indexOf("country");
     while (query.next()) {
         QString country = query.value(fieldNo).toString();
         doSomething(country);
     }

If you read the documentation, this question will be answered within a few 
minutes.
What I do find lacking is often a description of how the data model of the 
relationship between the classes. For example, it is never stated explicitely 
that a (preferably graphically) that a query contains records, and a record 
fields. You sort of have to figure this out for yourself. That would help one 
to know that if you can't find the functionality on the parent (query) you 
may have to look on the child (record).
Besides that, I find the QT documentation to be quite good. You just need to 
do a lot of reading, which I think anyone should. Somebody writes all that 
stuff: you should reward them by reading it ;-)
The overview pages in the assistant are quite usefull (this is where they give 
you an overview of a particular module, including a description of all the 
classes and what they do.)
And if all else fails, you can always use the ultimate two Manuals.

--
 [ signature omitted ] 

Message 7 in thread

On Dec 13, 2007, at 2:25 PM, Eric Methorst wrote:

> On Thursday 13 December 2007 18:22:41 Israel Brewster wrote:
>> On Dec 13, 2007, at 3:51 AM, Bo Thorsen wrote:
> <SNIP/>
>> This is just one example of many that I have run into in trying to
>> learn Qt where there is a function I need, but the closest thing I  
>> can
>> find takes as an argument some piece of non-obvious data which I have
>> to use other functions to find, ad infinitum. This is in spite of
>> trying to do something that I would think would be fairly easy, such
>> as the above example - see my messages to this list from early  
>> October
>> Re: Efficient data retrieval. Having such convenience functions   
>> would
>> make it easier to find the methods I needed, not harder, even though
>> the total number of available methods would be increased.
>>
> This is straight from the top part of the documentation:
> ==> To convert a field name into an index, use record().indexOf(),   
> <==
> or example:
>     QSqlQuery query("SELECT * FROM artist");
>     int fieldNo = query.record().indexOf("country");
>     while (query.next()) {
>         QString country = query.value(fieldNo).toString();
>         doSomething(country);
>     }
>
> If you read the documentation, this question will be answered within  
> a few
> minutes.

Sort of- there is still no indication that you don't have to go  
through the extra step of converting a field name into an index just  
to get the value of a specific field. Besides, this is only one  
example, there have been others I have come across where I have had to  
do quite a bit of digging and stringing functions together to get the  
desired result. Perhaps a better example would be when I needed to get  
the value of a column of the selected row in a QTreeView. As far as I  
an determine, first you have to figure out the selected row, for which  
you first have to get the currentIndex. That alone took me some time  
to track down, as only currentIndex is listed under the QTreeView  
documentation, and there was no indication that it could be used to  
get the current row. Once you have that piece of info, you then have  
to pass it into the record function previously discussed, and use the  
sub-functions of the record to access the data. As far as I could  
determine, that whole process is not documented, even though I would  
think "get the value of this column from the current selection" would  
be a fairly common task.

>
> What I do find lacking is often a description of how the data model  
> of the
> relationship between the classes. For example, it is never stated  
> explicitely
> that a (preferably graphically) that a query contains records, and a  
> record
> fields. You sort of have to figure this out for yourself. That would  
> help one
> to know that if you can't find the functionality on the parent  
> (query) you
> may have to look on the child (record).
> Besides that, I find the QT documentation to be quite good. You just  
> need to
> do a lot of reading, which I think anyone should. Somebody writes  
> all that
> stuff: you should reward them by reading it ;-)

Yep, that's for sure :-) The first thing I open before beginning  
development is the documentation, and I am constantly switching to and  
from it trying to get things to work. I just can't count the number of  
times I have been looking for a function to accomplish something for  
an extended period of time, only to eventually find a way three  
function calls deep and no where near where I would have thought to  
look.

>
> The overview pages in the assistant are quite usefull (this is where  
> they give
> you an overview of a particular module, including a description of  
> all the
> classes and what they do.)

That is true. And overall, I have found the documentation to be, as  
you say, quite good. It's just when I have to go several levels up the  
inheritance tree, and/or three or four nested function calls to get to  
what I would think should be an easy result that I start getting  
annoyed :-)


-----------------------------------------------
Israel Brewster
Computer Support Technician
Frontier Flying Service Inc.
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7250 x293
-----------------------------------------------

>
> And if all else fails, you can always use the ultimate two Manuals.
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx  
> with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/

--
 [ signature omitted ] 

Message 8 in thread

I have recently installed Microsoft Visual C++ 2008 Express Edition
I have successfully configured Qt with the command: configure -platform 
win32-msvc
But when trying to build Qt using the command: nmake, I run into the 
following error:-
---------------------------------------------------------------------------------------

NMAKE : fatal error U1077: 'rc' : return code '0x1'
Stop.


NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio9.0\VC\BIN
\nmake.exe"': return code '0x2'
Stop.


NMAKE : fatal error U1077: 'cd' : return code '0x2'
Stop.

---------------------------------------------------------------------------------------
I am new to all of this, so any suggestions/comments are most welcome.

Bob
New Zealand

--
 [ signature omitted ] 

Message 9 in thread

Hi Bob,

Are you building from the snapshot (what date) or the release?    (I was
able to build the 4.3.3-snapshot-20071207 with MSVC++ 2005 Express a few
days back, but the snapshot generation process seem to be quite flaky in
general)

On Dec 13, 2007 9:36 PM, Bob Matthews <rgmatthews@xxxxxxxxxxxx> wrote:

> NMAKE : fatal error U1077: 'rc' : return code '0x1'
> Stop.
>

I think we'll need the 4 or 5 lines immediately before to tell what's wrong.

Cheers,

-G

-- 
 [ signature omitted ] 

Message 10 in thread

Hello Garth
Thank you for replying........
I am building from the release...(have no experience with snapshots)
The attached jpg file shows the lines prior to the error.
Many thanks for your assistance
Bob
New Zealand


Garth Dahlstrom wrote:
> Hi Bob,
>
> Are you building from the snapshot (what date) or the release?    (I 
> was able to build the 4.3.3-snapshot-20071207 with MSVC++ 2005 Express 
> a few days back, but the snapshot generation process seem to be quite 
> flaky in general)
>
> On Dec 13, 2007 9:36 PM, Bob Matthews <rgmatthews@xxxxxxxxxxxx 
> <mailto:rgmatthews@xxxxxxxxxxxx>> wrote:
>
>     NMAKE : fatal error U1077: 'rc' : return code '0x1'
>     Stop.
>
>
> I think we'll need the 4 or 5 lines immediately before to tell what's 
> wrong.
>
> Cheers,
>
> -G

JPEG image

JPEG image


Message 11 in thread

Hello Bob,

Your jpg says "'rc' is not recognized as an internal or an external command",
which means that rc.exe is missing, at least in your PATH. Make sure to run
vsvars32.bat before you compile. May be this is a problem with VC++ 8 Express.
If rc.exe is missing, copy it from the PSDK / VC++ 2005 Express.

Cheers,

Quoting Bob Matthews <rgmatthews@xxxxxxxxxxxx>:

> Hello Garth
> Thank you for replying........
> I am building from the release...(have no experience with snapshots)
> The attached jpg file shows the lines prior to the error.
> Many thanks for your assistance
> Bob
> New Zealand

-- 
 [ signature omitted ] 

Message 12 in thread

<SNIP/>
> Sort of- there is still no indication that you don't have to go
> through the extra step of converting a field name into an index just
> to get the value of a specific field. Besides, this is only one
> example, there have been others I have come across where I have had to
> do quite a bit of digging and stringing functions together to get the
> desired result. Perhaps a better example would be when I needed to get
> the value of a column of the selected row in a QTreeView. As far as I
> an determine, first you have to figure out the selected row, for which
> you first have to get the currentIndex. That alone took me some time
> to track down, as only currentIndex is listed under the QTreeView
> documentation, and there was no indication that it could be used to
> get the current row. Once you have that piece of info, you then have
> to pass it into the record function previously discussed, and use the
> sub-functions of the record to access the data. As far as I could
> determine, that whole process is not documented, even though I would
> think "get the value of this column from the current selection" would
> be a fairly common task.
Yes, I've never enjoyed the model/view stuff myself either. I'd rather use a 
QTreeWidget any day. If you're going for the model/view stuff you shuold be 
prepared that the API becomes a little more... well... interesting :-)

So what exactly is it that you're doing? Binding a QSqlQuery to a QTreeView? 
Sounds interesting.
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body. List archive and information:
> http://lists.trolltech.com/qt-interest/


--
 [ signature omitted ] 

Message 13 in thread

On lørdag den 15. December 2007, Eric Methorst wrote:
> Yes, I've never enjoyed the model/view stuff myself either. I'd rather use
> a QTreeWidget any day. If you're going for the model/view stuff you shuold
> be prepared that the API becomes a little more... well... interesting :-)

The model view classes are really hard to get started with. But I guarantee 
you that for any non trivial project, the time investment will pay off 
immensely later. For maintainability, nothing beats the new model view 
classes.

Bo.

-- 
 [ signature omitted ] 

Message 14 in thread

On Dec 16, 2007, at 11:23 PM, Bo Thorsen wrote:

> On lørdag den 15. December 2007, Eric Methorst wrote:
>> Yes, I've never enjoyed the model/view stuff myself either. I'd  
>> rather use
>> a QTreeWidget any day. If you're going for the model/view stuff you  
>> shuold
>> be prepared that the API becomes a little more... well...  
>> interesting :-)
>
> The model view classes are really hard to get started with. But I  
> guarantee
> you that for any non trivial project, the time investment will pay off
> immensely later. For maintainability, nothing beats the new model view
> classes.

Ah, that explains a lot. I chose to introduce myself to Qt with a  
section of the API that was "really hard to get started with". No  
wonder it was a bit rough for the first couple weeks :-D.

-----------------------------------------------
Israel Brewster
Computer Support Technician
Frontier Flying Service Inc.
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7250 x293
-----------------------------------------------
>
>
> Bo.
>
> -- 
>
> Thorsen Consulting ApS - Qt consulting services
> http://www.thorsen-consulting.dk
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx  
> with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>

--
 [ signature omitted ] 

Message 15 in thread

On Dec 15, 2007, at 1:37 PM, Eric Methorst wrote:

> <SNIP/>
>> <SNIP/>
> So what exactly is it that you're doing? Binding a QSqlQuery to a  
> QTreeView?
> Sounds interesting.

Well, QSqlQueryModel to be specific, but yeah. My application  
interfaces with a postgresql back-end (although thanks to the way Qt  
works with databases, changing to another option would be trivial)  
using, in various places, practically the whole gamut of QSqlXYZ data  
models, and displays the data in, primarily, QTreeViews. I chose those  
over the QTableView because for my purposes at least the QTreeView has  
a cleaner interface. I really do enjoy the whole model/view paradigm  
in general, it's just the initial difficulty in finding the functions  
I need that bugs me :). Once I figured it out, it worked quite well.

-----------------------------------------------
Israel Brewster
Computer Support Technician
Frontier Flying Service Inc.
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7250 x293
-----------------------------------------------

>
>> --
>> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx  
>> with
>> "unsubscribe" in the subject or the body. List archive and  
>> information:
>> http://lists.trolltech.com/qt-interest/
>
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx  
> with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/

--
 [ signature omitted ] 

Pages: Prev | 1 | 2 | Next