Interesting, I haven't seen it. Thanks (it can lead to big mess, through).
|
At last something you didn't know! ;-)
|
This used to work on QT3:
Code:
qWarning("Dominio: " + dominio->text()); 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*, ...)’ |
you need to convert the whole string to a c-style string. Use the toStdString() method of the QString class.
|
...Or you can use the new QMessageBox class
Code:
QMessageBox::information(this |
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; |
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()))); (If you just want some diagnostics then you can use std::string and std::cout) graeme. |
It works with "new QTableWidgetItem()" too. Thanks!
Can you give me examples of the use of std::string and std::cout? :scratch: |
Oops! The linker is complaining a lot!
Code:
principal.o: in the function `Principal::btnBuscarClicked()': |
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. |
I think that you can do the following:
Code:
std::cout << "Dominio: " << dominio->text().toStdString(); graeme. |
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). |
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. |
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()) { |
Is the data actually held in the object consulta? Check you database connections. How are they done?
graeme. |
I guess so:
Code:
database = QSqlDatabase::addDatabase("QMYSQL3"); |
so what do you get back from consulta.size()?
What happens next? The while code or some other code first? graeme |
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? |
Okay obvious but, do you initialise i to zero before entering the loop?
|
Oh, you are right! That's my mistake. :-O
Just kidding. Yes, I do. :-) int i = 0; |
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(); graeme. |
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! :-) |
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).
|
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 |
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: |
All times are GMT -5. The time now is 09:45 AM. |