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

Sunday, May 8th 2005, 7:11pm

how can i insert more lines from qt in the post?

how can i insert more lines from qt in the post? #?

Source code

1
void Form1::playsound()

2

Sunday, May 8th 2005, 7:18pm

RE: how can i insert more lines from qt in the post?

ok here again:

i want to play the next song if the first are finished.But qt play allways the next bevor playing the first.

Quoted


void Form1::playsound()
{
listView->setFocus();


if (listView->currentItem() == 0){
QMessageBox::information(this,
("Info"),
("List is Empty"));
}


else{
QSound::play("/firma2/jukebox/sounds/" + feld_le->text()+"/" + ( listView->currentItem() )->text( 0 ) + "");
}

QSound soundend("/firma2/jukebox/sounds/" + feld_le->text()+"/" + ( listView->currentItem() )->text( 0 ) + "");


if(soundend.isFinished()){

QSound::play("/firma2/jukebox/sounds/mario/bassdrum");
}
}


dimitri

Professional

  • "dimitri" is male

Posts: 1,311

Occupation: Engineer

  • Send private message

3

Sunday, May 8th 2005, 7:21pm

RE: how can i insert more lines from qt in the post?

The indenting of your code is still unusual to the least. It's unreadable. Could you try to format and indent it properly?

Posts: 2,162

Location: Graz, Austria

Occupation: Student

  • Send private message

4

Sunday, May 8th 2005, 7:33pm

Create a sound object for each sound you want to play instead of using the static play method!

Cheers,
_
Qt/KDE Developer
Debian User

5

Sunday, May 8th 2005, 7:51pm

play dont need a object!
isfinished need one, and i have allready done!See code

I think my problem is here:

Quoted


if(soundend.isFinished()){

QSound::play("/firma2/jukebox/sounds/mario/bassdrum");
}



Posts: 2,162

Location: Graz, Austria

Occupation: Student

  • Send private message

6

Sunday, May 8th 2005, 8:59pm

Ok, even one single sentence seems to be too complex for you.
I'll try more fool proof

static QSound::play bad

QSound* sound = new QSound(filename);
sound->play()
good

Reason:
sound->stop() possible
sound->isFinished() returning value related to sound

Cheers,
_
Qt/KDE Developer
Debian User

7

Sunday, May 8th 2005, 9:33pm

thanks.but it did not work yet.

this part work well:

Quoted


void Form1::playsound()
{
listView->setFocus();


if (listView->currentItem() == 0){
QMessageBox::information(this,
("Info"),
("List is Empty"));
}


else{

QSound* sound = new QSound("/firma2/jukebox/sounds/" + feld_le->text()+"/" + ( listView->currentItem() )->text( 0 ) + "");
sound->play();
}


but this part not:

Quoted


QSound* sound = new QSound("/firma2/jukebox/sounds/" + feld_le->text()+"/" + ( listView->currentItem() )->text( 0 ) + "");

if(sound.isFinished()){

QSound* playnext = new QSound("/firma2/jukebox/sounds/mario/bassdrum");
playnext->play();
}
}

Posts: 2,162

Location: Graz, Austria

Occupation: Student

  • Send private message

8

Sunday, May 8th 2005, 9:37pm

I really, really hope you are calling isFinished on the correct oject.
The one which is playing.

Cheers,
_
Qt/KDE Developer
Debian User

9

Sunday, May 8th 2005, 9:41pm

yes it is or not?

10

Sunday, May 8th 2005, 9:45pm

Quoted


QSound* sound = new QSound("/firma2/jukebox/sounds/" + feld_le->text()+"/" + ( listView->currentItem() )->text( 0 ) + "");

if(sound->isFinished()){

QSound* playnext = new QSound("/firma2/jukebox/sounds/mario/bassdrum");
playnext->play();
}

11

Sunday, May 8th 2005, 9:56pm

if a call the function playsound(), Qt play allway just:

Quoted


if(sound->isFinished()){
QSound* playnext = new QSound("/firma2/jukebox/sounds/mario/bassdrum");
playnext->play();
}


Why?

Posts: 2,162

Location: Graz, Austria

Occupation: Student

  • Send private message

12

Monday, May 9th 2005, 10:22am

Quoted

Originally posted by marioo
yes it is or not?


Well, I am asking you!

You only posted parts of the new code, if you still have the double object construction from your old code, you have to read up on the concept of objects.

Cheers,
_
Qt/KDE Developer
Debian User

  • "wysota" is male

Posts: 4,276

Location: Warsaw, POLAND

  • Send private message

13

Monday, May 9th 2005, 10:30am

Quoted

Originally posted by marioo

Quoted


QSound* sound = new QSound("/firma2/jukebox/sounds/" + feld_le->text()+"/" + ( listView->currentItem() )->text( 0 ) + "");

if(sound->isFinished()){

QSound* playnext = new QSound("/firma2/jukebox/sounds/mario/bassdrum");
playnext->play();
}


Do you play the first sound (sound) at all? Because here you just create an object and check if it finished playing (without even starting it).

14

Monday, May 9th 2005, 11:42am

by click my button, i call the function playsound();
this function have to play first the selected item(sound).
And if the selected song(sound) is finish i want to play the next sound(playnext).But he dont play the selected (sound)first.Why?

He play just the next (playnext)!

here the code again:

Quoted


void Form1::playsound()
{
listView->setFocus();


if (listView->currentItem() == 0){
QMessageBox::information(this,
("Info"),
("List is Empty"));
}


else{

QSound* sound = new QSound("/firma2/jukebox/sounds/" + feld_le->text()+"/" + ( listView->currentItem() )->text( 0 ) + "");
sound->play();
}

QSound* sound = new QSound("/firma2/jukebox/sounds/" + feld_le->text()+"/" + ( listView->currentItem() )->text( 0 ) + "");

if(sound->isFinished()){

QSound* playnext = new QSound("/firma2/jukebox/sounds/mario/bassdrum");
playnext->play();
}
}





  • "wysota" is male

Posts: 4,276

Location: Warsaw, POLAND

  • Send private message

15

Monday, May 9th 2005, 12:11pm

Quoted

Originally posted by marioo

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
//...
else{
    QSound* sound = new QSound("/firma2/jukebox/sounds/" + feld_le->text()+"/" + ( listView->currentItem() )->text( 0 ) + "");
    sound->play();
}
 
QSound* sound = new QSound("/firma2/jukebox/sounds/" + feld_le->text()+"/" + ( listView->currentItem() )->text( 0 ) + "");

if(sound->isFinished()){

     QSound* playnext = new QSound("/firma2/jukebox/sounds/mario/bassdrum");
    playnext->play();
}

First you start playing the first entry and them immediately the variable runs out of scope (which means that you can't control it anymore and it gets deleted but the QSound object still exists, you just can't access it any longer) and then you create another sound and you check if that newly created sound is playing and because it is not, you play it causing probably the previous sound to be stopped.

You should have a timer that would periodically check if the previous sound finished playing and if it did, spawn the next sound. And you definitely need to improve your C++ knowledge especially about local variables. And next time, please use the code tag instead of quote and indent your code to make it a bit more readable.

16

Monday, May 9th 2005, 1:03pm

how complicated is that?I dont have idea how to beginn...

  • "wysota" is male

Posts: 4,276

Location: Warsaw, POLAND

  • Send private message

17

Monday, May 9th 2005, 2:14pm

Begin by writing down what exactly you want to achieve and then think about how it can be done, I mean how would you do it without a computer. Don't skip obvious things, don't assume that something is done automatically. Then come back with the list and we'll see what we can do for you :) Oh, and don't expect us to write your program for you, all we do is help and give hints.

18

Monday, May 9th 2005, 2:43pm

1. play sound1
2. check time from sound1
3. if time from sound1is finished
4. play sound2


1. QSound::Play()
2. QTimer
3. QSound::isFinished
4. QSound::Play()

is that ok?

  • "wysota" is male

Posts: 4,276

Location: Warsaw, POLAND

  • Send private message

19

Monday, May 9th 2005, 2:46pm

Quoted

Originally posted by marioo
is that ok?


No. I asked you how would YOU (as a human) do it -- what things need to be done to achieve your goal. Forget that Qt even exists now, just think what actions need to be taken to do what you want. Then you can "translate" them to C++ code.

And I mean detailed actions, it won't be three or four items. You have to think, wheather the application should wait for something in a particular moment, etc.

Posts: 2,162

Location: Graz, Austria

Occupation: Student

  • Send private message

20

Monday, May 9th 2005, 2:54pm

Quoted

Originally posted by marioo
how complicated is that?I dont have idea how to beginn...


It is not compliucated, it is in fact very easy if one understands objects in the real world.

If you have to apples and you eat one of them, you won't wonder why the other one is still not eaten.

How difficult is it to map that to sound objects?
If you create two objects for the same sound file and you start one, why do you expect the other object to change?

Cheers,
_
Qt/KDE Developer
Debian User