class defintions and implementations in a Qt program

Nov 1, 2011 at 12:57am
I am trying to figure out how the syntax of a simple Qt example program works.
I don't even know how to explain my question to search for it so if my word usage sounds wrong, sorry.
The complete code can be obtained here:
http://www.tuxradar.com/content/code-project-create-media-player

But in the header file the MainWindow class derives from QMainWindow and thats it.
But in the implementation file it has multiple inheritance and derives from QMainWindow and , Ui::MainWindowClass. how can that be?
Now I understand that the MainWindowClass is defined during compile time by running uic on a file named MainWindow.ui and that a header file: ui_MainWindow.h is created. but
I am unaware of any syntax which instantiates a class using the new operator in the class definition and how it translates into multiple inheritance and also why in the header file this multiple inheritance is not defined there.

Any help would be appreciated. Can you point me in the right direction?

I mean the program works, I've compiled it using qmake and cmake. God knows why :)

MainWindow.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#ifndef MAINWINDOW_H
#define MAINWINDOW_H


#include <QtGui/QMainWindow>
#include <QList>
#include <QFileDialog>
#include <QDesktopServices>

#include <QDebug>

#include <phonon/MediaObject>
#include <phonon/AudioOutput>

namespace Ui
{
    class MainWindowClass;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = 0);
    ~MainWindow();

private slots:
    void playPause();
    void addFiles();
    void nextFile();
    void aboutToFinish();
    void finished();

private:
    Ui::MainWindowClass *ui;

    bool state;

    QList<Phonon::MediaSource> sources;

    Phonon::MediaObject *mediaObject;
    Phonon::AudioOutput *audioOutput;
    Phonon::MediaObject *metaInformationResolver;
};

#endif // MAINWINDOW_H 


MainWindow.cpp snippet

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), ui(new Ui::MainWindowClass)
{

     audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
     mediaObject = new Phonon::MediaObject(this);
     metaInformationResolver = new Phonon::MediaObject(this);

     connect(mediaObject, SIGNAL(aboutToFinish()), this, SLOT(aboutToFinish()));
     connect(mediaObject, SIGNAL(finished()), this, SLOT(finished()));

     mediaObject->setTickInterval(1000);

     Phonon::createPath(mediaObject, audioOutput);

     ui->setupUi(this);

     ui->pushButtonPlay->setCheckable(true);
}

Last edited on Nov 1, 2011 at 3:59pm
Nov 10, 2011 at 4:27pm
I got my answer at Qt Forums:
http://www.qtforum.org/article/36901/help-with-mutliple-inheritance-understanding-syntax-of-example-qt-program.html?s=03123e23e0dc9390f1fe76ac5e9aee6cddf0dd7f

its not multiple inheritance, it was a member initialization list. Sorry I'm still learning quite a bit.
Topic archived. No new replies allowed.