LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   .ui.h / kdevelop question (https://www.linuxquestions.org/questions/programming-9/ui-h-kdevelop-question-395714/)

Mara 01-16-2006 04:57 PM

Interesting, I haven't seen it. Thanks (it can lead to big mess, through).

eantoranz 01-16-2006 05:06 PM

At last something you didn't know! ;-)

eantoranz 01-17-2006 12:37 PM

This used to work on QT3:

Code:

qWarning("Dominio: " + dominio->text());
(dominio is a QLineEdit)

But now it doesn't work with QT4.
This is the message from make:
Code:

error: cannot cast ‘const QString’ to ‘const char*’ for argument ‘1’ for ‘void qWarning(const char*, ...)’
(or something like that, I had to translate it from spanish).

graemef 01-17-2006 12:42 PM

you need to convert the whole string to a c-style string. Use the toStdString() method of the QString class.

graemef 01-17-2006 01:07 PM

...Or you can use the new QMessageBox class

Code:

QMessageBox::information(this
                        ,"Application name here"
                        ,"Dominio: " + dominio->text());

graeme.

eantoranz 01-17-2006 01:33 PM

That would be ok, but I just want a message to show up in my console, not in a window. I made the change you suggested before, and now the compiler says it can't convert from std::string to char *. It's ok if I just comment those lines (by now)... they're just debugging messages, no big deal (again, by now)... but look at this next problem (and this has me :scratch:):

Code:

int i = 0;
while (query.next()) {
        records->setItem(i, 0, QTableWidgetItem(query.value(1).toString()));
        i++;
}

And the compiler says it can't find a matching function for QTableWidget::setItem(int&, int , QTableWidgetItem)... and please, notice the & of int&. Where does that come from? i is just an int, right? :scratch:

graemef 01-17-2006 01:47 PM

It is expecting the TableWidgetItem to be passed as a pointer. Don't worry about the reference the compiler does that because you have passed a variable rather than a literal. So try:

Code:

records->setItem(i, 0, &(QTableWidgetItem(query.value(1).toString())));
and you should be okay.


(If you just want some diagnostics then you can use std::string and std::cout)

graeme.

eantoranz 01-17-2006 02:01 PM

It works with "new QTableWidgetItem()" too. Thanks!

Can you give me examples of the use of std::string and std::cout? :scratch:

eantoranz 01-17-2006 02:06 PM

Oops! The linker is complaining a lot!

Code:

principal.o: in the function `Principal::btnBuscarClicked()':
principal.cpp:(.text+0x1d0): reference to `QSqlDatabase::QSqlDatabase()' undefined
principal.cpp:(.text+0x1fb): reference to `QSqlQuery::QSqlQuery(QString const&, QSqlDatabase)' undefined
principal.cpp:(.text+0x229): reference to `QSqlDatabase::~QSqlDatabase()' undefined
principal.cpp:(.text+0x28e): reference to `QSqlQuery::prepare(QString const&)' undefined
.
.
.

What did I do in my past life to deserve this punishment? :'( :-D

graemef 01-17-2006 02:14 PM

Looks as if the linker is not including the QT files. You may need to check your QMake. Sorry I've not actually got access to any of my make files to see what they look like for a comparison :(

graeme.

graemef 01-17-2006 02:17 PM

I think that you can do the following:

Code:

std::cout << "Dominio: " << dominio->text().toStdString();

graeme.

eantoranz 01-17-2006 02:38 PM

about cout: It hasn't worked. Not as std::cout, not std::out (just in case), not cout.

about the linker. I have to add QT += sql in the qmake file. I have another problem (about the same). I'll research a little to see if I can solve it myself. If it's important, I'll post it here (either I solve it or not).

eantoranz 01-17-2006 02:46 PM

I think it's because I have libqt3-mt-mysql installed in my box... not for QT4. Any recomendations? I'll try to find the package, but maybe there's another easier way.

Firts, I was told -lqp wasn't find by the linker. I edited the Makefile and deleted it (just to test), now It's asking for -lmysqlclient.

eantoranz 01-23-2006 11:43 AM

I installed the package libqt4-sql and that was it.

Now, I'm running the application, but I don't get to see any data from the DB in my QTableWidget. :(

Code:

while (consulta.next()) {
        registros->setItem(i, 0, new QTableWidgetItem(consulta.value(1).toString())); // date
        registros->setItem(i, 1, new QTableWidgetItem(consulta.value(0).toString())); // string
        i++;
}

What am I missing?

graemef 01-23-2006 12:33 PM

Is the data actually held in the object consulta? Check you database connections. How are they done?

graeme.

eantoranz 01-24-2006 11:51 AM

I guess so:

Code:

database = QSqlDatabase::addDatabase("QMYSQL3");
database->setDatabaseName("databasename");
database->setUserName("username");
database->setPassword("password");
database->setHostName("hostname");

if (!database->open()) {
        qWarning( "Failed to open database: " + database->lastError().text() );
        QMessageBox::critical(this, "Error", database->lastError().text(), QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton);
        exit(1);
}

QSqlQuery consulta;//("select * from registro");
if (! consulta.prepare("select dominio, hora, host, hostname, usuario from registro where dominio like ? and hora between ? and ?")) {
        qWarning( "Fallo la compilacion de la consulta: " + database->lastError().text() );
        QMessageBox::critical(this, "Error", database->lastError().text(), QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton);
        return slotDetener();
}
consulta.bindValue(0, "%" + dominio->text() );
consulta.bindValue(1, desde->date() );
consulta.bindValue(2, hasta->date().addDays(1) );

if (! consulta.exec()) {
        qWarning( "Fallo la ejecucion de la consulta: " + database->lastError().text() );
        QMessageBox::critical(this, "Error", database->lastError().text(), QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton);
        return slotDetener();
}

qDebug( "Registros devueltos: %d", consulta.size() );

and so on.

graemef 01-24-2006 12:11 PM

so what do you get back from consulta.size()?

What happens next? The while code or some other code first?

graeme

eantoranz 01-24-2006 12:56 PM

consulta.size() gives me 942 records (that's what's expected).

then set the QTableWidget to have consulta.size() rows then the while to fill out information in the table (that would be the while I posted before). :scratch: what am I forgetting to do?

graemef 01-24-2006 01:13 PM

Okay obvious but, do you initialise i to zero before entering the loop?

eantoranz 01-24-2006 01:37 PM

Oh, you are right! That's my mistake. :-O

Just kidding. Yes, I do. :-)

int i = 0;

graemef 01-24-2006 01:58 PM

Just a thought the size() method might put the pointer to the end of the list of records. Can you make a first() call just before the loop.

Code:

consulta.first();
while (consulta.next()) {
        registros->setItem(i, 0, new QTableWidgetItem(consulta.value(1).toString())); // date
        registros->setItem(i, 1, new QTableWidgetItem(consulta.value(0).toString())); // string
        i++;
}

If that fails what do you get from an isActive() and an isSelect() ?

graeme.

eantoranz 01-25-2006 09:47 AM

Oh, man.. just hand me a knife! :-)

I was linking against the wrong version of libmysql-client. The linker was already telling me about the problem, I just didn't notice it. I removed the 1.4, installed the 1.2 and I'm back on track again!

Thank you, graemef, for you r help. I'll keep in touch in case something comes up... so I guess I'll be back soon! :-)

eantoranz 01-25-2006 11:26 AM

OK. I'm on windows now trying to run the application I just tested in linux. What do I have to do now so that I can work with a mysql DB? I'm getting a beautiful message saying: "Driver not loaded Driver not loaded" (like that, twice the same message in a single message box).

graemef 01-25-2006 11:46 AM

You probably need to compile the MySQL driver for windows. See the QT documentation here

Other obvious question is have you included the QT += sql parameter in the project file?

graeme

eantoranz 01-25-2006 12:03 PM

I guess I know where the problem is from. I hadn't built the debug libraries.

I'm running it right now. But I see this:

Code:

Sql Drivers:
    ODBC....................plugin
    MySQL...................no
    OCI.....................no
    PostgreSQL..............no
    TDS.....................no
    DB2.....................no
    SQLite..................plugin
    SQLite2.................no
    InterBase...............no

See the NO for mysql? Is there a light at the end of the tunnel?


All times are GMT -5. The time now is 09:45 AM.