You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Wednesday, December 5th 2007, 2:12pm

Problem opening the QFileDialog

Hi! I am trying to write a simple media player for linux using QT 4.3.2. I have one main window where i have put a button that opens the playlist window. In the playlist window i have put a listwidget and a button which opens a file dialog in order to add songs to the list. But there is a problem with the code which opens the filedialog. This code is in a custom slot. My code in my custom slot is:

Source code

1
private slots: void AddFiles() { QFileDialog filedialog(this); filedialog.exec(); }

And the messages i get are:

Source code

1
FormPlaylist.h:74: error: no matching function for call to ‘QFileDialog::QFileDialog(Ui_DialogPlaylist* const, Qt::WFlags)’/usr/include/qt4/QtGui/qfiledialog.h:247: note: candidates are: QFileDialog::QFileDialog(const QFileDialog&)/usr/include/qt4/QtGui/qfiledialog.h:240: note: QFileDialog::QFileDialog(const QFileDialogArgs&)/usr/include/qt4/QtGui/qfiledialog.h:92: note: QFileDialog::QFileDialog(QWidget*, const QString&, const QString&, const QString&)/usr/include/qt4/QtGui/qfiledialog.h:88: note: QFileDialog::QFileDialog(QWidget*, Qt::WindowFlags)
If i comment out the code which opens the filedialog then the program compiles successfully. I have included <QtGui/QFileDialog> and my IDE is Kdevelop 4:3.5.0-2 with g++ compiler version 4:4.2.1-6. I have followed the example of QT Assistant in the QFileDialog section and other examples on the net with no success. What can i do? Thanks in advance

Seth666

Beginner

  • "Seth666" is male

Posts: 20

Location: Poland

  • Send private message

2

Wednesday, December 5th 2007, 4:19pm

The constructor you want to use takes as a aparent argument class which has to inherit from QWidget, probably your class declaration should look like this

Quoted

class Ui_DialogPlaylist: public QWidget (and other classes if you need) {....};

This post has been edited 1 times, last edit by "Seth666" (Dec 5th 2007, 4:21pm)


3

Wednesday, December 5th 2007, 4:34pm

Quoted

Originally posted by Seth666
The constructor you want to use takes as a aparent argument class which has to inherit from QWidget, probably your class declaration should look like this

Quoted

class Ui_DialogPlaylist: public QWidget (and other classes if you need) {....};


I'm almost sure you're right!

also remember to include the qtFileDialog or other for enabling use it.
I'm looking for job in japan as computer engineer... so you know... If you need a mate tell to the boss ;)

Seth666

Beginner

  • "Seth666" is male

Posts: 20

Location: Poland

  • Send private message

4

Wednesday, December 5th 2007, 4:57pm

he included, otherwise the compiler error will be something like this

Quoted

Undefined reference to......

not a

Quoted

no matching function for call to....

5

Wednesday, December 5th 2007, 5:58pm

Thank you very much for your help. It worked but appeared other problems. I tried multiple inheritance by writing

Source code

1
 class Ui_DialogPlaylist: public QWidget, QObject

but i got many errors:

Source code

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
 FormPlaylist.h:40: warning: direct base ‘QObject’ inaccessible in ‘Ui_DialogPlaylist’ due to ambiguity
FormPlaylist.h: In member function ‘void Ui_DialogPlaylist::setupUi(QDialog*)’:
FormPlaylist.h:68: error: reference to ‘connect’ is ambiguous
/usr/include/qt4/QtCore/qobject.h:292: error: candidates are: bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
/usr/include/qt4/QtCore/qobject.h:191: error: candidates are: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)
/usr/include/qt4/QtCore/qobject.h:292: error: bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
/usr/include/qt4/QtCore/qobject.h:191: error: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)
FormPlaylist.h:68: error: reference to ‘connect’ is ambiguous
/usr/include/qt4/QtCore/qobject.h:292: error: candidates are: bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
/usr/include/qt4/QtCore/qobject.h:191: error: candidates are: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)
/usr/include/qt4/QtCore/qobject.h:292: error: bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
/usr/include/qt4/QtCore/qobject.h:191: error: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)
FormPlaylist.h:69: error: reference to ‘connect’ is ambiguous
/usr/include/qt4/QtCore/qobject.h:292: error: candidates are: bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
/usr/include/qt4/QtCore/qobject.h:191: error: candidates are: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)
/usr/include/qt4/QtCore/qobject.h:292: error: bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
/usr/include/qt4/QtCore/qobject.h:191: error: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)
FormPlaylist.h:69: error: reference to ‘connect’ is ambiguous
/usr/include/qt4/QtCore/qobject.h:292: error: candidates are: bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
/usr/include/qt4/QtCore/qobject.h:191: error: candidates are: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)
/usr/include/qt4/QtCore/qobject.h:292: error: bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
/usr/include/qt4/QtCore/qobject.h:191: error: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)
FormPlaylist.h:70: error: reference to ‘connect’ is ambiguous
/usr/include/qt4/QtCore/qobject.h:292: error: candidates are: bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
/usr/include/qt4/QtCore/qobject.h:191: error: candidates are: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)
/usr/include/qt4/QtCore/qobject.h:292: error: bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
/usr/include/qt4/QtCore/qobject.h:191: error: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)
FormPlaylist.h:70: error: reference to ‘connect’ is ambiguous
/usr/include/qt4/QtCore/qobject.h:292: error: candidates are: bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
/usr/include/qt4/QtCore/qobject.h:191: error: candidates are: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)
/usr/include/qt4/QtCore/qobject.h:292: error: bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
/usr/include/qt4/QtCore/qobject.h:191: error: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)

I searched the net and found that i cannot inherit more than one qt class in each class. But how i am going to have QObject inherited in order to use "connect" ? This is the first problem. After that i wrote the class as

Source code

1
 class Ui_DialogPlaylist: QObject
and then i wrote the AddFiles() slot as

Source code

1
2
3
4
5
6
void AddFiles()
{
cout << "in addfilesn";
//QFileDialog filedialog(this);
//filedialog.exec();
}
Also my "connect" code is

Source code

1
2
3
connect(btnaddfiles, SIGNAL( released() ), this, SLOT( AddFiles() ) );
connect(btnremove, SIGNAL( released() ), this, SLOT( RemoveFromPlaylist() ) );
connect(btnclearlist, SIGNAL( released() ), this, SLOT( ClearPlaylist() ) );

It successfully compiled but when i pressed the "btnaddfiles" it didn't write nothing to the console. That means that it doesn't actually connect the button "btnaddfiles" with the slot. But on the other hand i don't get messages such as "Object::connect: No such slot" during the runtime like the button and the slot are connected. I don't know if this is important but the "DialogPlaylist" form is being opened from a button on another form which is and the main window of the application. Any help is appreciated!

Seth666

Beginner

  • "Seth666" is male

Posts: 20

Location: Poland

  • Send private message

6

Wednesday, December 5th 2007, 7:47pm

just inherit from QWidget, the problem is that you are trying to inherit two times from QObject. class QWidget inherits QObject (it is a second line in documentation :) so your class shouldn't do this again.

also

you have to run Q_OBJECT macro so the classs definitin will be:

Source code

1
2
3
4
5
6
7
class Ui_DialogPlaylist: public QWidget
{
   Q_OBJECT  //just this
   
   ...... //
   .......//everything else 
};

7

Wednesday, December 5th 2007, 8:44pm

I didn't know about QWidget that inherits QObject. I am new to QT as you have already understood. I have already included Q_OBJECT and it doesn't work

Seth666

Beginner

  • "Seth666" is male

Posts: 20

Location: Poland

  • Send private message

8

Wednesday, December 5th 2007, 10:12pm

what types are those btnaddfiles, btnremove and btn.... ?? (declaration and connect() are in the same class?)
and slot functions are declarated in section
public slots:
not just
public:
??

9

Wednesday, December 5th 2007, 10:22pm

The types of the buttons are QPushButton and yes all are in the same class. I have written the slots under a "private slots:" section. Maybe you can find a solution by examining the whole code:

Source code

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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
 #ifndef FORMPLAYLIST_H
#define FORMPLAYLIST_H

#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QDialog>
#include <QtGui/QListWidget>
#include <QtGui/QPushButton>
#include <QtGui/QFileDialog>
#include <iostream>
using namespace std;

class Ui_DialogPlaylist: public QWidget
{
Q_OBJECT
public:
QPushButton *btnaddfiles;
QPushButton *btnremove;
QPushButton *btnclearlist;
QListWidget *lstplaylist;

void setupUi(QDialog *DialogPlaylist)
{
if (DialogPlaylist->objectName().isEmpty())
DialogPlaylist->setObjectName(QString::fromUtf8("DialogPlaylist"));
DialogPlaylist->resize(265, 236);
btnaddfiles = new QPushButton(DialogPlaylist);
btnaddfiles->setObjectName(QString::fromUtf8("btnaddfiles"));
btnaddfiles->setGeometry(QRect(0, 190, 75, 31));
btnremove = new QPushButton(DialogPlaylist);
btnremove->setObjectName(QString::fromUtf8("btnremove"));
btnremove->setGeometry(QRect(70, 190, 111, 31));
btnclearlist = new QPushButton(DialogPlaylist);
btnclearlist->setObjectName(QString::fromUtf8("btnclearlist"));
btnclearlist->setGeometry(QRect(180, 190, 75, 31));
lstplaylist = new QListWidget(DialogPlaylist);
lstplaylist->setObjectName(QString::fromUtf8("lstplaylist"));
lstplaylist->setGeometry(QRect(0, 0, 256, 192));

retranslateUi(DialogPlaylist);

connect(btnaddfiles, SIGNAL( released() ), this, SLOT( AddFiles() ) );
connect(btnremove, SIGNAL( released() ), this, SLOT( RemoveFromPlaylist() ) );
connect(btnclearlist, SIGNAL( released() ), this, SLOT( ClearPlaylist() ) );

QMetaObject::connectSlotsByName(DialogPlaylist);
} // setupUi

void retranslateUi(QDialog *DialogPlaylist)
{
DialogPlaylist->setWindowTitle(QApplication::translate("DialogPlaylist", "Playlist", 0, QApplication::UnicodeUTF8));
btnaddfiles->setText(QApplication::translate("DialogPlaylist", "Add files", 0, QApplication::UnicodeUTF8));
btnremove->setText(QApplication::translate("DialogPlaylist", "Remove from list", 0, QApplication::UnicodeUTF8));
btnclearlist->setText(QApplication::translate("DialogPlaylist", "Clear list", 0, QApplication::UnicodeUTF8));
Q_UNUSED(DialogPlaylist);
} // retranslateUi

private slots:
void AddFiles()
{
cout << "in addfilesn";
//QFileDialog filedialog(this);
//filedialog.exec();
}

void RemoveFromPlaylist()
{
lstplaylist->removeItemWidget(lstplaylist->currentItem());
}
void ClearPlaylist()
{
lstplaylist->clear();
}

};

namespace Ui {
class DialogPlaylist: public Ui_DialogPlaylist {};
} // namespace Ui

#endif // FORMPLAYLIST_H

Seth666

Beginner

  • "Seth666" is male

Posts: 20

Location: Poland

  • Send private message

10

Wednesday, December 5th 2007, 11:06pm

hmmmm

the problem is interesting, i compiled this code and guess what?
nothig, zero errors, it works (i comiled only this code you gave me)
try to do the same,

11

Thursday, December 6th 2007, 8:38am

Yes you are right! The code is working and the button is connected with the slot. But only when the playlist form is lauched directly from main.cpp. My program structure is: main.cpp creates an instance of another class, the MainWindow class and launches it. MainWindow class is of type QMainWindow and it is the main window of the program that has a information about the song, buttons such as play, stop and other buttons which opens other forms such as the playlist form. Now i noticed that when the playlist form is launched normally from MainWindow form then appears the problem with the slots but when it is launched directly from main.cpp then everything works. What a strange problem! Ok i think that you will need and the MainWindow class source:

Source code

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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
 #ifndef FORMMAINWINDOW_H
#define FORMMAINWINDOW_H

#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QFrame>
#include <QtGui/QLabel>
#include <QtGui/QMainWindow>
#include <QtGui/QPushButton>
#include "FormPlaylist.h"
#include <iostream>

using namespace std;

class Ui_MainWindow: QObject
{
Q_OBJECT
public:
QWidget *centralwidget;
QFrame *frame;
QLabel *lblsongtitle;
QLabel *lblsongtitle_3;
QPushButton *btnnext;
QPushButton *btnplaypause;
QPushButton *btnstop;
QLabel *lblsongtitle_2;
QLabel *lblsongduration;
QLabel *lblsongplayed;
QPushButton *btnprevious;
QLabel *lblsongtitle_4;
QLabel *lblstatus;
QPushButton *btnplaylist;

void setupUi(QMainWindow *MainWindow)
{
if (MainWindow->objectName().isEmpty())
MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
MainWindow->resize(312, 162);
MainWindow->setDockOptions(QMainWindow::AllowTabbedDocks|QMainWindow::AnimatedDocks);
centralwidget = new QWidget(MainWindow);
centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
frame = new QFrame(centralwidget);
frame->setObjectName(QString::fromUtf8("frame"));
frame->setGeometry(QRect(0, 0, 311, 131));
frame->setFrameShape(QFrame::StyledPanel);
frame->setFrameShadow(QFrame::Raised);
lblsongtitle = new QLabel(frame);
lblsongtitle->setObjectName(QString::fromUtf8("lblsongtitle"));
lblsongtitle->setGeometry(QRect(0, 0, 54, 22));
lblsongtitle_3 = new QLabel(frame);
lblsongtitle_3->setObjectName(QString::fromUtf8("lblsongtitle_3"));
lblsongtitle_3->setGeometry(QRect(0, 40, 54, 22));
btnnext = new QPushButton(frame);
btnnext->setObjectName(QString::fromUtf8("btnnext"));
btnnext->setGeometry(QRect(150, 90, 60, 31));
btnplaypause = new QPushButton(frame);
btnplaypause->setObjectName(QString::fromUtf8("btnplaypause"));
btnplaypause->setGeometry(QRect(30, 90, 60, 31));
btnplaypause->setMaximumSize(QSize(16777215, 16777215));
btnstop = new QPushButton(frame);
btnstop->setObjectName(QString::fromUtf8("btnstop"));
btnstop->setGeometry(QRect(90, 90, 60, 31));
lblsongtitle_2 = new QLabel(frame);
lblsongtitle_2->setObjectName(QString::fromUtf8("lblsongtitle_2"));
lblsongtitle_2->setGeometry(QRect(0, 20, 54, 22));
lblsongduration = new QLabel(frame);
lblsongduration->setObjectName(QString::fromUtf8("lblsongduration"));
lblsongduration->setGeometry(QRect(250, 20, 54, 22));
lblsongduration->setLayoutDirection(Qt::RightToLeft);
lblsongplayed = new QLabel(frame);
lblsongplayed->setObjectName(QString::fromUtf8("lblsongplayed"));
lblsongplayed->setGeometry(QRect(250, 40, 54, 22));
lblsongplayed->setLayoutDirection(Qt::RightToLeft);
btnprevious = new QPushButton(frame);
btnprevious->setObjectName(QString::fromUtf8("btnprevious"));
btnprevious->setGeometry(QRect(210, 90, 60, 31));
lblsongtitle_4 = new QLabel(frame);
lblsongtitle_4->setObjectName(QString::fromUtf8("lblsongtitle_4"));
lblsongtitle_4->setGeometry(QRect(0, 60, 54, 22));
lblstatus = new QLabel(frame);
lblstatus->setObjectName(QString::fromUtf8("lblstatus"));
lblstatus->setGeometry(QRect(250, 60, 54, 22));
lblstatus->setLayoutDirection(Qt::RightToLeft);
btnplaylist = new QPushButton(centralwidget);
btnplaylist->setObjectName(QString::fromUtf8("btnplaylist"));
btnplaylist->setGeometry(QRect(230, 130, 75, 31));
btnplaylist->setAcceptDrops(false);
btnplaylist->setDefault(false);
btnplaylist->setFlat(false);
MainWindow->setCentralWidget(centralwidget);

retranslateUi(MainWindow);

connect(btnplaylist, SIGNAL( released() ), this, SLOT( OpenPlaylist() ));

QMetaObject::connectSlotsByName(MainWindow);
} // setupUi

void retranslateUi(QMainWindow *MainWindow)
{
MainWindow->setWindowTitle(QApplication::translate("MainWindow", "Linamp", 0, QApplication::UnicodeUTF8));
lblsongtitle->setText(QApplication::translate("MainWindow", "xxx", 0, QApplication::UnicodeUTF8));
lblsongtitle_3->setText(QApplication::translate("MainWindow", "Played :", 0, QApplication::UnicodeUTF8));
btnnext->setText(QApplication::translate("MainWindow", "Next", 0, QApplication::UnicodeUTF8));
btnplaypause->setText(QApplication::translate("MainWindow", "Play", 0, QApplication::UnicodeUTF8));
btnstop->setText(QApplication::translate("MainWindow", "Stop", 0, QApplication::UnicodeUTF8));
lblsongtitle_2->setText(QApplication::translate("MainWindow", "Duration :", 0, QApplication::UnicodeUTF8));
lblsongduration->setText(QApplication::translate("MainWindow", "xxx", 0, QApplication::UnicodeUTF8));
lblsongplayed->setText(QApplication::translate("MainWindow", "xxx", 0, QApplication::UnicodeUTF8));
btnprevious->setText(QApplication::translate("MainWindow", "Previous", 0, QApplication::UnicodeUTF8));
lblsongtitle_4->setText(QApplication::translate("MainWindow", "Status :", 0, QApplication::UnicodeUTF8));
lblstatus->setText(QApplication::translate("MainWindow", "xxx", 0, QApplication::UnicodeUTF8));
btnplaylist->setText(QApplication::translate("MainWindow", "Open playlist", 0, QApplication::UnicodeUTF8));
Q_UNUSED(MainWindow);
} // retranslateUi

private slots:
void OpenPlaylist()
{
QDialog *playlistdialog = new QDialog;
cout << "inside openplaylistn";
Ui_DialogPlaylist playlist;
playlist.setupUi(playlistdialog);
playlistdialog->show();
}

};

namespace Ui {
class MainWindow: public Ui_MainWindow {};
} // namespace Ui

#endif // FORMMAINWINDOW_H

And my main.cpp source is

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <QApplication>
#include <QMainWindow>
#include <QDialog>
#include "FormMainwindow.h"
#include "FormPlaylist.h"
#include <iostream>
using namespace std;

int main(int argc, char *argv[])
{
cout << "startedn";
QApplication app(argc, argv);
QMainWindow * mainwindow = new QMainWindow;
//QDialog * mainwindow = new QDialog;
Ui_MainWindow x;
//Ui_DialogPlaylist x;
x.setupUi(mainwindow);
mainwindow->show();

return app.exec();
}

I wish you can help me with this strange problem!

This post has been edited 1 times, last edit by "NGF" (Dec 6th 2007, 8:39am)


Seth666

Beginner

  • "Seth666" is male

Posts: 20

Location: Poland

  • Send private message

12

Thursday, December 6th 2007, 12:57pm

bleee
you have to recode your aplication litle, your code is very, hmm...., dirty.
it' s only my opinion, i will give you some advice, as i can see you are new in QT, but you have good start.
if i'm creating a QT application my main.cpp file looks like this (usually)

Source code

1
2
3
4
5
6
7
8
9
10
#include <QApplication>
#include "MainWindow.h"

 int main(int argc, char *argv[])
 {
     QApplication app(argc, argv);
     MainWindow window;
     window.show();
     return app.exec();
 }


i the file MainWindow. i have a class declaration (this class inherits QMainWindow)

Source code

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
#include <QWidget>
#include <QAction>
#include <QMainWindow>
#include <QtGui>
#include <QFileDialog>
#include <QString>
#include "InfoWidget.h"
#include "ImageWidget.h"

class MainWindow:public QMainWindow
{
Q_OBJECT
public:
	MainWindow();
	~MainWindow(); //you don't have to use destructor
private:
     QPushButton *button;

    InfoWidget *widget; //as you can see i'am also using other classes, you will probable insert here some other widget
     //
     // everything else, methods, slots
    /// you should insert here your buttons "next", "previous"
    // 


};

this is example code for application that i'm actually trying to create

and the creating off all those buttons cames in constructor

Source code

1
2
3
4
5
6
7
8
MainWindow::MainWindow()
{
	button1= new QPushButton("button1", this);
...............
...............
...............

}


The poin is:
1. I have one main class, that is handling main window
2. If some other window should be open it is also in main window, not in file main.cpp

if you want, to se my app (i started it two days ago so it is not working yet, but main window and opening a file works) here it is:

http://fatcat.ftj.agh.edu.pl/~seth/qt_program/

if you have any questions, just write
i will aswer as soon as possible

This post has been edited 1 times, last edit by "Seth666" (Dec 6th 2007, 12:59pm)


13

Thursday, December 6th 2007, 4:35pm

I have changed main.cpp as follows:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 #include <QApplication>
#include <QMainWindow>
#include <QDialog>
#include "FormMainwindow.h"
#include "FormPlaylist.h"
#include <iostream>
using namespace std;

int main(int argc, char *argv[])
{
cout << "startedn";
QApplication app(argc, argv);
//QMainWindow * mainwindow = new QMainWindow;
//QDialog * mainwindow = new QDialog;
//Ui_MainWindow x;
//Ui_DialogPlaylist x;
//x.setupUi(mainwindow);
Ui_MainWindow mainwindow;
mainwindow.show();

return app.exec();
}

But i get some errors:

Source code

1
2
3
 /usr/include/qt4/QtGui/qwidget.h:463: error: ‘void QWidget::show()’ is inaccessible
main.cpp:38: error: within this context
main.cpp:38: error: ‘QWidget’ is not an accessible base of ‘Ui_MainWindow’


I tried changing "class Ui_MainWindow: QMainWindow" in the mainwindow class to "class Ui_MainWindow: public QMainWindow" and the errors disappeared but it was launched a blank window and propably because first you have to call setupUi method of the main window class in order to setup the window

I saw your source. I understood the way but it seems to be QT3. Do you use QT3?. I am using QT4 and the 2 classes were generated by uic. I added to both classes the Q_OBJECT, custom slots code and the "connect" code. Do i have to change the qt4 uic generated code to qt3 way or maybe use qt3? But generally is time consuming changing every qt4 uic generated code to qt3 style of code

This post has been edited 1 times, last edit by "NGF" (Dec 6th 2007, 4:40pm)


Seth666

Beginner

  • "Seth666" is male

Posts: 20

Location: Poland

  • Send private message

14

Thursday, December 6th 2007, 6:16pm

no, i'm using the QT 4.3.2

and i told, that you should delete your setupUI() method and write everythimg in class constructor.

in my code is no method setupSomething(), all is in constructor (and believe me it's a good and elegant way of coding)

also my method is faster, in your program compiler has to build a constructor because you haven't any
and next you are calling additional method setupUI()

15

Friday, December 7th 2007, 1:00pm

Ok i followed your advice and changed the code. Now everything is working. The btnaddfiles is connected with the slot and the QFileDialog opens. Thank you very much for your help! You saved me!!