PDA

View Full Version : QSLQuery and progress messages



dcypher
1st April 2013, 21:42
Hello I need to capture the progress messages generated when I execute the query ANALYZE VERBOSE, actually the messages are printed in the qDebug, What I need is to show those messages in a text box of my app.

This is my query:

QSqlQuery query(bd_seleccionada);
query.exec("ANALYZE VERBOSE;");


Help PLEASE!!!!

wysota
1st April 2013, 22:03
A progress of what? exec() returns only the final output of the query you send to the server.

dcypher
1st April 2013, 22:45
when I execute the query, it shows me a lot of messages in the qDebug, like these:
INFO: analyzing "pg_catalog.pg_type"
INFO: "pg_type": scanned 7 of 7 pages, containing 315 live rows and 0 dead rows; 315 rows in sample, 315 estimated total rows
INFO: analyzing "pg_catalog.pg_attribute"
INFO: "pg_attribute": scanned 38 of 38 pages, containing 2181 live rows and 0 dead rows; 2181 rows in sample, 2181 estimated total rows
INFO: analyzing "pg_catalog.pg_authid"
INFO: "pg_authid": scanned 1 of 1 pages, containing 11 live rows and 0 dead rows; 11 rows in sample, 11 estimated total rows
INFO: analyzing "pg_catalog.pg_class"
INFO: "pg_class": scanned 7 of 7 pages, containing 284 live rows and 1 dead rows; 284 rows in sample, 284 estimated total rows
.......
I need to capture thoses messages and put them in a text box.

wysota
1st April 2013, 23:30
QSqlQuery will not help you with that.

dcypher
2nd April 2013, 02:03
any idea of how to capture those messages?? Is there a way to capture the text printed by qDebug??

ChrisW67
2nd April 2013, 04:21
The messages are output by the PostgreSql directly to one of your processes standard streams, i.e. not from Qt and not via QDebug. If you cannot use a simple command line redirection, e.g. "run_my_program 2>error.txt", then you would need to redirect the std::cerr (maybe std::cout) streams of your program to a string buffer or file. Plenty of guidance on how to do that on the 'net e.g. http://stackoverflow.com/questions/5419356/redirect-stdout-stderr-to-a-string

If you only want the results then they are left in a PostgreSQL system table.

Lesiok
2nd April 2013, 07:39
any idea of how to capture those messages?? Is there a way to capture the text printed by qDebug??

Yes, read about qInstallMsgHandler (http://qt-project.org/doc/qt-4.8/qtglobal.html#qInstallMsgHandler)

dcypher
2nd April 2013, 21:54
The messages are output by the PostgreSql directly to one of your processes standard streams, i.e. not from Qt and not via QDebug. If you cannot use a simple command line redirection, e.g. "run_my_program 2>error.txt", then you would need to redirect the std::cerr (maybe std::cout) streams of your program to a string buffer or file. Plenty of guidance on how to do that on the 'net e.g. http://stackoverflow.com/questions/5419356/redirect-stdout-stderr-to-a-string

If you only want the results then they are left in a PostgreSQL system table.

I try this but it still does not capture any message, and the messages are still printed by the qDebug. This is my code, please help meeee!!!:

std::stringstream buffer;
std::streambuf * old = std::cerr.rdbuf(buffer.rdbuf());
//these messages are what i want to capture
consulta->Analyze();//here i do query.exec("ANALYZE VERBOSE")
//this is captured ok
std::cerr << "Error";//this works
std::string text = buffer.str();

QString msg = QString::fromStdString(text);

ChrisW67
3rd April 2013, 02:31
As risk of sounding like a broken record:

The messages are output by the PostgreSql directly ... , i.e. not from Qt and not via QDebug.
Did you try redirecting std::cout? Have you asked the PostgreSQL people how you might do this?

dcypher
3rd April 2013, 19:38
yes I 've tryed with std::cout and still no messages, i almost give up, may be there's no way doing this. What makes me anger is that I can see the messages printed by the qDebug console BRRR!!!!

wysota
3rd April 2013, 19:45
Those messages are not printed by "qDebug console". They are printed by libpq.

dcypher
4th April 2013, 21:21
any idea of how to capture them?? please an example will be very usefull, i'm just begining in c++ and my english is very poor.

wysota
4th April 2013, 21:27
Ask at some PostgreSQL forum, this has nothing to do with Qt.