PDA

View Full Version : QWebKit, QDataStream, QList



Viper666
18th September 2012, 19:22
Hallo I have 2 problems:
1. I do WebBrowser and when I set Application name
QApplication a(argc, argv);
a.setApplicationName("MyBrowser");
Window w;
or

QCoreApplication::setApplicationName(QLatin1String ("MyBrowser"));
QCoreApplication::setApplicationVersion(QLatin1Str ing("0.1"));
now signal iconChanged() never emit but when i don't set Application name all work good

2. I take all history items to QList<QAction *> history;
save function:
QFile historyFile("/History.bin");
if(!historyFile.open(QIODevice::WriteOnly))
{
return;
}
QDataStream out(&historyFile);
out.setVersion(QDataStream::Qt_4_8);
out << allHistoryAction;
historyFile.flush();
historyFile.close();
all work but in load:

QFile historyFile("/History.bin");
if(!historyFile.open(QIODevice::ReadOnly))
{
return;
}
QDataStream in(&historyFile);
in.setVersion(QDataStream::Qt_4_8);
in >> allHistoryAction;
historyFile.close();
this don't work error:
error: no match for 'operator>>' in 's >> t'

Viper666
19th September 2012, 15:00
Please I need it. The most important is second question i can't save history

norobro
19th September 2012, 20:47
The answer is in the docs: link (http://doc-snapshot.qt-project.org/4.8/qlist.html#operator-gt-gt)

Viper666
20th September 2012, 13:33
??? i don' understand I use QDatastream operator>> but i have error if i do something bad pls post me some code

norobro
20th September 2012, 14:21
From the linked page:
This function requires the value type to implement operator>>()QAction does not have operator>>() or operator()<< implemented so you have to implement them.

Something like the following:
QDataStream & operator<< (QDataStream & outputStream, const QAction *act){
outputStream << act->text() << act->shortcut(); // any properties you want to store
return outputStream;
}

QDataStream & operator>> (QDataStream & inputStream, QAction *&action){
action = new QAction(0);
QString text;
QKeySequence seq;
inputStream >> text >> seq;
action->setText(text);
action->setShortcut(seq);
return inputStream;
}

Viper666
20th September 2012, 14:49
ok thanks but i don't know why operator << work and operator >> not

Viper666
21st September 2012, 13:49
and one else question i don't know how save connect or how connect all actions in list again