Problem with QtCreator application <MediaPlayer> with list of videos through databases
-
Hi,
i have a little problem with my Qt application. In my function MediaPlayer, i´ve tried to create list of videos through QSqlDatabases, as i´ve gone further, the more i ruined it .. I can repair it to function state, but i really need that list. I have no idea where is problem, maybe it is because i am new in programing. Sorry for that.If there is someone who can tell me how to complete my application, or how to solve this error. It would be really great.
Here is my code:
https://mega.nz/#F!mYhURDAC!HyPVie-6oU7nZPJH-CwcGgThanks for all advices
Regards Qinyx
PS: Sorry for mistakes, i am not from english speaking country, i am from Czech Republic :)
-
Hi and welcome :)
You dont seem to open database at all or read from it.So where IS this DB file ?
You must supply more details for us to help.
If its the "cannot not open SQL driver" error, then just search the forum.
tons of those for all platforms. :) -
Yeah, i know that database was not open at all, because of these errors, that i am not able to solve.
Screenshot: https://ctrlv.cz/gkj9
Normaly in any other application .db file is created in built_** file, but in this case it was not created. I tried to delete all lines that includes something connected with databases, to get clear MediaPlayer, and then tried to do it again. Unfortunatelly no result.
I am able to send you clear MediaPlayer, if you want. And if you are willing to rewrite/modify it to case, where i can easily add list/database connected with this media player. I would be really greatful.
Regards Qinyx
-
Hi
Its still not very clear what you want.
Do you want to STORE list in data base or to read a preexisting DB?Here is sample that creates a DB
bool createConnection() {
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(":memory:");
if (!db.open()) {
QMessageBox::critical(0, qApp->tr("Cannot open database"), "Click Cancel to exit.", QMessageBox::Cancel);
return false; }QSqlQuery query;
qDebug() << "table:" << query.exec("create table person (id int primary key, "
"firstname varchar(20), lastname varchar(20), num int )");
query.exec("insert into person values(101, 'Dennis', 'Young','1')");
query.exec("insert into person values(102, 'Christine', 'Holand','2')");
query.exec("insert into person values(103, 'Lars junior', 'Gordon','4')");
query.exec("insert into person values(104, 'Roberto', 'Robitaille','5')");
query.exec("insert into person values(105, 'Maria', 'Papadopoulos','3')");
return true;
}and you call it like this
createConnection(); QSqlQuery query; int ok = query.prepare("SELECT * from person "); query.exec(); while (query.next()) { QString name = query.value(1).toString(); // col 1 = name qDebug() << ">" << name; }
-
Well, what i want is really easy. I have media player, and when i will start any video, then it will add to list of played videos, and then append it into TextBrowser. Something like history. I know ho to create simple database without these connections, but i can not solve this problem i´ve got.
I know, i am annoying, but i need to learn it somehow. Sorry for that :P
Regards Qinyx
-
@Qinyx
So you can open database etc. ?So what is your actual true problem ?
and no, you are not annoying but its unclear which part that is not working for you.
The sample just makes the db in memory but easy to make it save to disk.I assume , you want is save history to DB and then on next start
open db and read in the history ? -
Hi,
I am sorry for late replying. I´ve used your advices, and it is finally working :)For comparasing here is my final code.
CODE: https://mega.nz/#F!mYhURDAC!HyPVie-6oU7nZPJH-CwcGg
Thank you very much.
Regards Qinyx