Qlabel is invisible...why?
Frank
frank at suffolkconnection.com
Thu Mar 7 02:59:02 UTC 2002
Hello all. I posted this in the Kdevelop forum but wanted to try and reach
help this way as well.
I am new to C++ so bear with the childish code. I was a Machine Language
programmer over 10 years ago and am now looking into trying a new language.
But I gotta tell ya, OOP is not as easy to swallow as Machine Language or
Assembly for that matter.
Here is the scenario. I am designing a small app to simply learn the QT
environment along witht the KDEcore where applicable.
The program is basic.
You simply pick wav files from the QFileDialog (one at a time for now),
After you've inserted the list of files you want to play, you simply hit the
play button.
Here is the problem:
I made a "Top Level?" modal widget window popup during playback so that it
can say "Playing..." (and maybe add the filename too later).
But with this widget pops up the QLabel text is not there.
BTW, When using the Debug feature and stepping through the area in question,
I noticed that the TheDialog widget does not show when the line
'TheDialog->show();' is executed but finally does appear when it reaches
'CommandLinez.start(KProcess::Block,KProcess::Stdin);'
But again, the QLabel portion of that widget is not appearing within the
'TheDialog' widget.
The rest works fine.
TIA,
Trodelec
Here is the code:
////////////////////////////////////////////////////////////////////////////
// learnprogramming.h
////////////////////////////////////////////////////////////////////////////
#include <qapplication.h>
#include <qwidget.h>
#include <qfiledialog.h>
#include <qstring.h>
#include <qdir.h>
#include <qpushbutton.h>
#include <qlistbox.h>
#include <qmessagebox.h>
#include <kprocess.h>
#include <stdlib.h>
#include <qlabel.h>
class MyMainWindowFSD:public QWidget
{
Q_OBJECT
public:
MyMainWindowFSD();
private:
QPushButton *b1;
QPushButton *b2;
QPushButton *b3;
QString RootDir;
QFileDialog *fdialog;
QString filez;
QString Ufilez;
QListBox *listbox;
QMessageBox *quitbox;
KProcess CommandLinez;
QLabel *labeld;
QWidget *TheDialog;
public slots:
void MyFileDialog();
void QuitProgram();
void UpLinkz();
};
////////////////////////////////////////////////////////////////////////////
// learnprogramming.cpp
////////////////////////////////////////////////////////////////////////////
#include "learnprogramming.h"
#include <qlabel.h>
int FileCounter=-1;
int i;
MyMainWindowFSD::MyMainWindowFSD()
{
setGeometry(100,100,400,300);
b1 = new QPushButton("Add File", this);
b1->setGeometry(20,20,100,40);
b1->setFont(QFont("Times",12,QFont::Bold));
b2 = new QPushButton("Quit", this);
b2->setGeometry(20,230,100,40);
b2->setFont(QFont("Times",12,QFont::Bold));
b3 = new QPushButton("Play", this);
b3->setGeometry(20,80,100,40);
b3->setFont(QFont("Times",12,QFont::Bold));
listbox = new QListBox(this);
listbox->setGeometry(150,20,230,250);
connect(b1,SIGNAL(clicked()),this,SLOT(MyFileDialog()));
connect(b2,SIGNAL(clicked()),this,SLOT(QuitProgram()));
connect(b3,SIGNAL(clicked()),this,SLOT(UpLinkz()));
}
void MyMainWindowFSD::MyFileDialog()
{
RootDir=QDir::homeDirPath();
filez=fdialog->getOpenFileName(RootDir, "*.wav");
if(filez.isNull()==FALSE)
{
listbox->insertItem(filez);
FileCounter++;
}
}
void MyMainWindowFSD::QuitProgram()
{
QMessageBox quitbox("Proceed with Quit?", "Do you really want to quit?",
QMessageBox::Information,
QMessageBox::Yes | QMessageBox::Default,
QMessageBox::No | QMessageBox::Escape,
0);
switch (quitbox.exec())
{
case QMessageBox::Yes:
exit(0);
break;
case QMessageBox::No:
break;
}
}
void MyMainWindowFSD::UpLinkz()
{
TheDialog= new QWidget;
TheDialog->setCaption("Work In Progress");
TheDialog->setGeometry(10,10,200,60);
labeld= new QLabel(TheDialog);
labeld->setText("Playing File(s)...");
labeld->setGeometry(10,10,160,40);
labeld->setFont(QFont("Times",12,QFont::Bold));
labeld->setAlignment(AlignCenter);
for (i=FileCounter; i > -1; i--)
{
TheDialog->show();
KProcess CommandLinez;
CommandLinez.clearArguments();
CommandLinez <<"playwave";
Ufilez=listbox->text(i);
CommandLinez << Ufilez;
CommandLinez.start(KProcess::Block,KProcess::Stdin);
listbox->removeItem(i);
TheDialog->close();
}
}
////////////////////////////////////////////////////////////////////////////
//main.cpp
////////////////////////////////////////////////////////////////////////////
#include "learnprogramming.h"
int main( int argc, char ** argv )
{
QApplication a( argc, argv );
MyMainWindowFSD w;
a.setMainWidget(&w);
w.show();
return a.exec();
}
More information about the KDevelop-devel
mailing list