Blackberry MediaPlayer retrieves empty metaData - c++

I have a cascades project where I use the MediaPlayer class in cpp.
I have defined a handler class, which handles metaDataChanged event, but when I set the source url and call mediaPlayer.prepare() method, it doesn't retrieve anything in metadata, so it's simply empty QVariantMap.
What's interesting is that defined event handler for metaDataChaned event is not even called.
I think there could be something that I can add here to be able to get the metadata, however prepare() method workds sucessfully, so I don't know what's the problem
here is a piece of code I've tried.
bb::multimedia::MediaPlayer* mp = new bb::multimedia::MediaPlayer();
mp->setSourceUrl(resultString);
mp->prepare();
MetaDataReader metaDataReader(mp);
and a class
MetaDataReader::MetaDataReader(bb::multimedia::MediaPlayer* mediaPlayer) : QObject(NULL)
{
connect(mediaPlayer, SIGNAL(metaDataChanged(const QVariantMap&)), this, SLOT(onMetaDataChanged(const QVariantMap&)));
}
void MetaDataReader::onMetaDataChanged(const QVariantMap& metaData)
{
someCode
// It doesn't reach this SLOT
}
How can I get the metadata here?
thanks in advance

It's a bit odd, but you may not get metadata until you start playback for the file. Try starting playback, and you should see the metaDataChanged signal get fired shortly after.

Related

call wxHyperlinkEvent without clicking on link

I am using wxHyperLink. OnHyperlinkClicked(wxHyperlinkEvent&) is called when user clicks on the link. OnHyperlinkClicked() helps to switch between 2 screens. I want to call this function explicitly - without user interaction.
I am using the following code for that:
BEGIN_EVENT_TABLE(UserRegistrationFrame, wxFrame)
EVT_HYPERLINK(wxID_ANY, UserRegistrationFrame::OnAuthCodeOptionLinkClicked)
END_EVENT_TABLE()
void MyClass::MyFunction()
{
wxHyperlinkEvent event;
OnAuthCodeOptionLinkClicked(event);
}
void MyClass::OnAuthCodeOptionLinkClicked(wxHyperlinkEvent& event)
{
// code to switch
}
Is this the correct way to achieve my goal? Or do I have to use something different?
The code is not correct, because with EVENT_TABLE you are setting a handler that doesn't exist.
When the user clicks on the control the event is fired, and the static table will call UserRegistrationFrame::OnAuthCodeOptionLinkClicked, not MyClass::OnAuthCodeOptionLinkClicked
I'd better forget EVENT_TABLES and go with Dynamic Event Handling. Using Bind() gives you more features.
Now, you want to call the event-handler function directly, not coming from a user action. Then you need to create an event just to pass it to the handler. That's what you do in MyClass::MyFunction(), right?
Don't mix jobs. If both your direct-call and the event-handler use a common feature, put it in a different function and call it directly or from the event-handler.
But the question is Why do you use a wxHyperlinkCtrl for a task like screen switching? Do you want also the default browser to be launched?

HOw to reload the present UI details once is switch from different UI in QT C++

I have two forms one is trainee_view.ui
and other is enter_new_trainee.ui
so for that i have trainee_view.cpp,trainee_view.h to see the list of Trainee in DB
and enter_new_trainee.cpp,enter_new_trainee.h to enter new trainee details
now in trainee_view.ui i have a push button "ADD Trainee"
so if i click this button it will go to "enter_new_trainee.ui"
void trainee_view::on_pushButton_2_clicked()
{
newtrainee=new enter_new_trainee(this);
newtrainee->setWindowFlags(Qt::Window);
newtrainee->show();
// connect(newtrainee, SIGNAL(destroyed()), this, SLOT(refresh_form()));
}
so by using connect() i am trying to refresh the trainee_view after entering the new trainee details. so how can i emmit the signal from
2nd form to 1st form such that i call refresh_form() method in 1st form .
I tried to use destroyed() signal on newtrainee but could not refresh my trainee_view form.
To be MOre simple . i just want to get an object is destroyed or not so if destroyed i can call refresh() method to load back the changes done on widget
for that i opted connect() method so how should i call that. becoz if i call
connect(newtrainee, SIGNAL(destroyed()), this, SLOT(refresh_form()));
there is no effect i.e nothing is loading into the view.
am newbie to qt so pls try to help me.
Thank YOu.
I'm not sure if I correctly understand your app, but I think you misunderstand the concept of Signals and Slots. Look here for some examples. In some simplification you can look at signal and slots this way: connect() command is a place which will not do anything - it just stay and keep listening for a signal. So you should place it in trainee_view.cpp. That's the first part and I see you did it correct, or almost correct. But you need also something that will send the signal, and this is exactly what emit() command do - it should be placed in enter_new_trainee.cpp just after description of generation new entry. For example, let assume user input new entry in LineEdit in UI:
[...]
QString newEntry = ui->LineEdit->text(); //Save entry to variable
emit(newEntry); //Emit it to signal slot
[...]

QML type from C++ Plugin signaling only once

I have a C++ plugin that watches for file changes with QFileSystemWatcher and connects it's fileChanged signal with a custom QML type slot like this:
//In the custom QML type constructor
QObject::connect(&this->_watcher, SIGNAL(fileChanged(QString)),
this, SLOT(fileChangedSlot(QString)));
The slot function:
void CustomQMLTypeClass::fileChangedSlot(QString file)
{
Q_UNUSED(file);
emit fileChanged();
}
In the QML side:
CustomQMLType{
fileUri: "some/file/path/file.format"
onFileChanged: console.log("File changed")
}
While running the program all goes right, but when I do, i.e.:
echo "sth" >> some/file/path/file.format
More than once, the notification is only triggered once. Why? O.o
Apparently the problem is with QFileSystemWatcher, it sometimes worked and some others don't.
As I can handle the cost, my quick solution was to alter the slot:
void CustomQMLTypeClass::fileChangedSlot(QString &file)
{
_watcher.removePath(file);
_watcher.addPath(file);
emit fileChanged();
}
Now it works as expected but don't know why and couldn't get to understand neither with QFileSystemWatcher's source. Finally I decided KDE's KDirWatch is way better.

Qml C++ Find Child

I have a main.qml with a MainPage.qml inserted through:
initialPage: MainPage {tools: toolBarLayout}
because I choose to make it for Symbian. When i try:
QObject *mainPage = rootObject->findChild<QObject*>("MainPage");
if (mainPage)
QDeclarativeProperty(mainPage, "toets").write(3);
the message doesn't come through but there are no errors, I have also tried connecting a SIGNAL to a SLOT on MainPage with the "if (mainPage)" but it also has no response. I have managed to get a signal through to main though but when I try:
function changeNum(num)
{
MainPage.changeNum(num)
}
The function never gets executed because I don't get a message from console.log at all unlike I do when the function on main runs. I also know the other methods didn't work because the also didn't log a message or execute the rest of their function.
I think the problem might lie in MainPage not being created as an element with a id. Do you know what might be causing this?
findChild doesn't look for the id but the objectName property which you can simply add inside the MainPage object (see the documentation):
initialPage: MainPage {
objectName: "MainPage"
tools: toolBarLayout
}
You could also access that object through the initialPage property of the rootObject without the need to add a objectName property:
QObject * mainPage = QDeclarativeProperty(rootObject, "initialPage").object();
if (mainPage)
QDeclarativeProperty(mainPage, "toets").write(3);

Configuring new document in MFC

When the user creates a new document in my SDI-application, I need to present a dialog specifying details on the document to be created (think: resolution, bit-depth, etc.) I initially put the code for displaying this dialog in OnNewDocument() (I don't need it when opening an existing document), but putting user-interface code in the document-class just doesn't feel right (also, I don't have any CWnd* to use as a parent for the dialog).
Is there a better place to do this in MFC?
You're right, the document class is no good place for UI.
CDocTemplate::[OpenDocumentFile][1](pszPath) looks like a better candidate:
pszPath==NULL means 'create a new document'.
The method is virtual -> Just derive CMySingleDocTemplate from CSingleDocTemplate and use an instance of this class in CMyWinApp::InitInstance().
This class is responsible for creating docs, frames and views, hence I think it's a good place to put a UI operation.
BOOL CMyWinApp::InitInstance()
{
...
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CMySingleDocTemplate( // <--Derives from CSingleDocTemplate
IDR_MAINFRAME,
RUNTIME_CLASS(CMyDoc),
RUNTIME_CLASS(CMainFrame),
RUNTIME_CLASS(CMyView));
AddDocTemplate(pDocTemplate);
...
}
CDocument* CMySingleDocTemplate::OpenDocumentFile(LPCTSTR lpszPathName,
BOOL bMakeVisible)
{
CDocument *pDoc =
CSingleDocTemplate::OpenDocumentFile(lpszPathName, bMakeVisible);
if (lpszPathName==NULL)
{
// GUI to get user info
// update doc
m_pOnlyDoc->Blah(input);
// update view
m_pOnlyDoc->UpdateAllViews(NULL,...,...);
}
}
This might not be ideal though: In SDI, there is one and only doc object. It's re-used accross File/Load and File/New operation.
This function will then be called a first time before the initial mainframe is created. You may not want to have a dialog presented to user before the frame is created. Ouch! It's a little more complicated:
Instead of popping up a GUI in in OpenDocumentFile(NULL) as above, just post a custom message/command to the main frame. Then add a handler that will react by the sequence pop up GUI/update doc/update views. That way, the main frame will be displayed before the GUI is popped up and your user will be happier.
This also solves your problem where you don't have a CWnd parent: the main frame is already created and your dialog will use it byt default.
BTW, another solution consists in adding a command handler for ID_FILE_NEW in your CMyWinApp's message map and add your own override of OnFileNew(). But when you write OnFileNew(), I believe you'll quickly find out that it's an ugly solution :-(