PDA

View Full Version : QuickTime API



merry
8th February 2008, 12:30
Hi all

http://doc.trolltech.com/qq/qq20-hiviews.html

I had used the above API of QuickTime to display movies , but the problem is
that i am having a list of files in QTreeWidget , on double click on an item , I am saving the file and then calling this API , the file Plays , but sometimes after playing some files, when i click on another file to play ,the balnk screen displays but the movie widget and controllers are not visible on the screen, I dont know why it is happening.

Regards
Merry

jpn
8th February 2008, 12:37
So, what do you expect us to do without giving a single line of code?

merry
8th February 2008, 12:46
I had given the link , In this link Full Source code is available for displaying movies (himovieview), I used same code , but the difference is this much only that in this , file is selected using QFileDialog and I am selecting file using QTreeWidget, that is I am having a QTreeWidget , in which there is a list of files, and on double click on the file , the player is being visible and load the file.

Regards
Merry

merry
11th February 2008, 05:57
Hi all

I think there is a problem of Memory Leakage in the QuickTime Player API. (http://doc.trolltech.com/qq/qq20-hiviews.html).
Source code is available in the above link
Can anybody tells me How to handle the problem of Memory leakage in this API.

Regards
Merry

jpn
11th February 2008, 08:24
I had given the link , In this link Full Source code is available for displaying movies (himovieview), I used same code , but the difference is this much only that in this , file is selected using QFileDialog and I am selecting file using QTreeWidget, that is I am having a QTreeWidget , in which there is a list of files, and on double click on the file , the player is being visible and load the file.
So, are you able to reproduce the problem with the example code? If not, most likely the problem is in your code.


I think there is a problem of Memory Leakage in the QuickTime Player API. (http://doc.trolltech.com/qq/qq20-hiviews.html).
Source code is available in the above link
Can anybody tells me How to handle the problem of Memory leakage in this API.
What actions did you take to verify that there is a memory leak? Also, I suppose you mean that the sample application has a memory leak.

merry
11th February 2008, 10:09
Thanks for the reply.

I saw it through the "ActivityMonitor"

Actually what i am exactly doing is this when the user double click on the file in the QTreeWidget, the file get saved and after saving the file , a signal is emitted for loading the movie in the MovieWidget, and when the movie is loaded , i 'll delete that saved file,

Through the activity monitor i saw , Till then free memory is available the files are loaded in the movie widget and when free space available is less than the file size then the widget appears but with no controllers , that is only a blank screen appears.

Then i thought its a Memory Leakage problem at the time of movie load.

Regards
Merry

merry
14th February 2008, 07:07
Hi all

I got the problem where the memory leaks.

On Every double click on the QTreeWidgetItem, When I call the QuickTimeMovie Player,then every time I' ll make the new Player, due to which there is lots of memory leakage.


Window *movieWindow = new Window(0);
connect(this,SIGNAL(movieChosen(QString)),movieWin dow,SLOT(OpenMovie(QString))),
movieWindow->show();


Is there any other way , that on doubleClick on the QTreeWidgetItem, I dont have to make the new Player.

If i make it member variable, then it crashes. what to do?


Regards
Merry

jpn
14th February 2008, 08:53
I got the problem where the memory leaks.

On Every double click on the QTreeWidgetItem, When I call the QuickTimeMovie Player,then every time I' ll make the new Player, due to which there is lots of memory leakage.
You allocate QObjects without parent and never delete them? Yes, that's a memory leak.



Is there any other way , that on doubleClick on the QTreeWidgetItem, I dont have to make the new Player.

If i make it member variable, then it crashes. what to do?
My wild guess is that even if you declare a member variable you assign to a local variable.

merry
14th February 2008, 10:07
Thanks 4 the reply


You allocate QObjects without parent and never delete them? Yes, that's a memory leak.

How can I stop this memory leak.


My wild guess is that even if you declare a member variable you assign to a local variable.

I declare it as a Global Variable.

jpn
14th February 2008, 10:58
How can I stop this memory leak.
Re-use same component or deallocate the previous one before allocating a new one.


I declare it as a Global Variable.
I'd advise not to do that. Using global variables tend to lead to unreadable and unmaintainable error-prone code.

merry
15th February 2008, 10:47
Hi


Re-use same component or deallocate the previous one before allocating a new one.


I am reusing the same component, but when i make it close, it crashes.


connect(btn_close, SIGNAL(clicked()), this, SLOT(close()));

and if I not close it using the above statement and close it using the close from the upper left corner , then it works fine,

What is the difference between the two close.

I had used the QPushButton to close ,To set the widget Modal.

Regards
Merry

jpn
15th February 2008, 11:07
I am reusing the same component, but when i make it close, it crashes.
Run your application via debugger and see the backtrace. Don't try to guess the reason. Use available tools to conclude the reason.


and if I not close it using the above statement and close it using the close from the upper left corner , then it works fine,

What is the difference between the two close.

I had used the QPushButton to close ,To set the widget Modal.
Sorry, I don't understand the problem description. Could you rephrase?

merry
15th February 2008, 11:29
Hi


Run your application via debugger and see the backtrace. Don't try to guess the reason. Use available tools to conclude the reason.

Really , i am not guessing.

Actually , I already told you that I am having a Widget , in Which there is a QTreeWidget, and when i double click on the QTreeWidgetItem ,i make the moviePlayer widget visible,
To set the moviePlayer widget modality , I use


moviePlayerwidget->setModality(QApplication::Modal)

due to which the Close button on the upperLeft corner dissapears. and for closing the moviePlayerwidget, I use


connect(btn_close, SIGNAL(clicked()), this, SLOT(close()));, using this
the process crashes.

But , if I wont set the modality , then the Close button on the upperLeft corner is visible,

and when i use Close button on the upperLeft corner to close, It not crashes,

I dont understand the difference between the two closes ,

Or

Tell me the other alternative , that without setting the modality ,moviePlayerWidget comes over the other widget. , because If I wont set the modality of moviePlayerWidget, It comes behind the other widget.

Hope so now you understand my problem.

Thanx

jpn
15th February 2008, 22:35
Really , i am not guessing.

Actually , I already told you that I am having a Widget , in Which there is a QTreeWidget, and when i double click on the QTreeWidgetItem ,i make the moviePlayer widget visible
Yes, that's what you have told us. However, that's extremely high-level description. Remember that we haven't seen a single line of code. There's really no way for us to help solving the problem if that's all what you tell us. You have to help us to help you. A backtrace mostly gives a clear picture of the situation when a crash occurs.

merry
19th February 2008, 07:56
Hi

In the below code when i tries to close the dialog ,through the button I used in Window class then application crashes, but if I close it through the close button that is on the upper left corner that is "X" then it wont crashes and works fine and also no memory leakage. For this I use QDialog.exec() , So that modality should also set and "X" should also be visible but, using this QDialog.exec() also "X" Should not be visible.


SelectFile.cpp

void SelectFile::init()
{
connect(btn_SelectFile,SIGNAL(clicked()),this,SLOT (chooseMovie()));
}

void SelectFile::chooseMovie()
{
QString TmpStr = QFileDialog::getOpenFileName(this);
EnterMovies();
if(movieWindow==NULL)
Window *movieWindow = new Window(0);
connect(this,SIGNAL(movieChosen(QString)),movieWin dow,SLOT(OpenMovie(QString)));
emit movieChosen(TmpStr);
movieWindow->exec();
ExitMovies();
}


window.cpp


Window::Window(QWidget *parent)
: QDialog(parent)
{
setupUi(this);
movieWidget = new MovieWidget(this);
connect(this, SIGNAL(movieChoose(QString)),movieWidget,SLOT(load Movie (QString)));
connect(movieWidget, SIGNAL(optimalSizeChange()),this, SLOT(updateSizes()));
connect(movieWidget, SIGNAL(NoPreview()),this, SIGNAL(NoPreviewAvailable()));
connect(btn_close, SIGNAL(clicked()), this, SLOT(Close()));
layout()->addWidget(movieWidget);
}

Window::~Window()
{

}

void Window::Close()
{
connect(this, SIGNAL(DisposeCurrentMovie()),movieWidget,SLOT(dis pose()));
close();
}
void Window :: OpenMovie(QString bMovieName)
{
emit movieChoose(bMovieName);
}
void Window::updateSizes()
{
adjustSize();
}


moviewidget.cpp

#include "moviewidget.h"
#include <QtGui/QLayout>
#include <Carbon/Carbon.h>
#include <QuickTime/QuickTime.h>

MovieWidget::MovieWidget(QWidget *parent)
: QWidget(parent), currentMovie(0)
{
HIViewRef movieView;
HIObjectCreate(kHIMovieViewClassID, 0, reinterpret_cast<HIObjectRef*>(&movieView));
HIMovieViewChangeAttributes(movieView,
kHIMovieViewAutoIdlingAttribute | kHIMovieViewControllerVisibleAttribute, 0);

create(WId(movieView));
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);

}

MovieWidget::~MovieWidget()
{
if (currentMovie)
DisposeMovie(currentMovie);
}

void MovieWidget::dispose()
{
if (currentMovie)
DisposeMovie(currentMovie);
}

void MovieWidget::loadMovie(const QString &fileName)
{
QTVisualContextRef visualContext = 0;
Boolean active = true;
DataReferenceRecord dataRef;
Movie oldMovie = 0;



// create an array of properties for NewMovieFromProperties
// these properties describe how to create the new movie
// see Movies.h for the full list of available properties
QTNewMoviePropertyElement newMovieProperties[] = {
{kQTPropertyClass_DataLocation, kQTDataLocationPropertyID_DataReference, sizeof(dataRef), &dataRef, 0},
{kQTPropertyClass_NewMovieProperty, kQTNewMoviePropertyID_Active, sizeof(active), &active, 0},
{kQTPropertyClass_Context, kQTContextPropertyID_VisualContext, sizeof(visualContext), &visualContext, 0},
};

CFStringRef cfString = CFStringCreateWithCharacters(0,
reinterpret_cast<const UniChar *>(fileName.unicode()),
fileName.length());
QTNewDataReferenceFromFullPathCFString(cfString, kQTPOSIXPathStyle, 0, &dataRef.dataRef, &dataRef.dataRefType);
CFRelease(cfString);


// if there's an old movie save it so we can dispose of it if
// we load up a new movie successfully
oldMovie = currentMovie;
currentMovie = 0;

// create a new movie using movie properties
// when calling this function, you supply a set of input properties that describe the information
// required to instantiate the movie (its data reference, audio context, visual context, and so on)
NewMovieFromProperties(sizeof(newMovieProperties) / sizeof(newMovieProperties[0]), // the number of properties in the array passed in inputProperties
newMovieProperties, // a pointer to a property array describing how to instantiate the movie
0, // number of properties in the array passed in outputProperties
0, // pointer to a property array to receive output parameters - 0 if you don’t want this information
&currentMovie); // pointer to a variable that receives the new movie
// make sure to dispose of the dataRef we no longer need it
DisposeHandle(dataRef.dataRef);

// set the HIMovieView's current movie
HIMovieViewSetMovie(HIViewRef(winId()), currentMovie);

if (oldMovie != 0)
DisposeMovie(oldMovie);

if(currentMovie == 0)
emit NoPreview();
// new movie has a new size, need to update.
updateGeometry();
emit optimalSizeChange();

}

QSize MovieWidget::sizeHint() const
{
EventRef event;
HIRect optimalBounds;
CreateEvent(0, kEventClassControl, kEventControlGetOptimalBounds,
GetCurrentEventTime(), kEventAttributeUserEvent, &event);
SendEventToEventTargetWithOptions(event,
HIObjectGetEventTarget(HIObjectRef(winId())),
kEventTargetDontPropagate);
GetEventParameter(event, kEventParamControlOptimalBounds, typeHIRect,
0, sizeof(HIRect), 0, &optimalBounds);
ReleaseEvent(event);
return QSize(optimalBounds.size.width, optimalBounds.size.height);
}

bool MovieWidget::nativeControlsVisible() const
{
OptionBits currentBits = HIMovieViewGetAttributes(HIViewRef(winId()));
return currentBits & kHIMovieViewControllerVisibleAttribute;
}

void MovieWidget::setNativeControlsVisible(bool visible)
{
if (visible != nativeControlsVisible()) {
HIMovieViewChangeAttributes(HIViewRef(winId()),
visible ? kHIMovieViewControllerVisibleAttribute : 0,
!visible ? kHIMovieViewControllerVisibleAttribute : 0);
updateGeometry();
emit optimalSizeChange();

}
}




Regards
Merry

jpn
19th February 2008, 08:09
I'm surprised it works at all.


if(movieWindow==NULL) // tests a member variable
Window *movieWindow = new Window(0); // assigns to a new local variable, NOT to the member variable
connect(this,SIGNAL(movieChosen(QString)),movieWin dow,SLOT(OpenMovie(QString))); // uses the member variable
emit movieChosen(TmpStr);
movieWindow->exec(); // uses the member variable

merry
19th February 2008, 08:13
if(movieWindow==NULL) // tests a member variable
Window *movieWindow = new Window(0);

Sorry By Mistake I had written this ,In my code I had taken it as a member Variable.


if(movieWindow==NULL) // tests a member variable
movieWindow = new Window(0);

jpn
19th February 2008, 08:17
The next step is to instantiate the modal dialog on the stack. You might also want to pass a proper parent to make dialog appear properly over its parent:


Window movieWindow(this); // parent
movieWindow.OpenMovie(TmpStr);
movieWindow.exec(); // blocks

merry
19th February 2008, 08:30
Thanks for the reply.
But on using this , Still "X" is dissabled, Is some flags to be set

merry
19th February 2008, 11:44
Using QDialog.exec() Still "All the three buttons are disabled" on the upper Left corner, that
is (x) (-) & (+).

Please tell me what should i do,

Regards
Merry

jpn
19th February 2008, 12:59
Could you compile and run the following test application?


// main.cpp
#include <QtGui>

int main(int argc, char* argv[])
{
QApplication a(argc, argv);
QDialog d;
return d.exec();
}

Does it look like you want?

merry
19th February 2008, 13:14
Thanx 4 the reply

I had run the application , and i got the result this , No I dont want this , I want close button (X) at the top should be visible.

Regards
Merry