You are not logged in.

Krasu

Beginner

  • "Krasu" started this thread

Posts: 30

Location: Republic of Belarus

  • Send private message

1

Tuesday, May 3rd 2005, 7:26pm

KDoubleSpinBox problem

KDoubleSpinBox::valueChaged(double) signal is not emmited! I connected it to some slot, but this slot is not executed:






When I press 'up' or 'down' arrow in spinbox, nothing happens, and there is no output to stdout. Whats wrong ?

Latem

Beginner

Posts: 31

Location: New Brunswick, Canada

Occupation: Student/Programmer

  • Send private message

2

Wednesday, May 4th 2005, 3:10am

hmm that is weird. the slider doesnt move either i gather?
than the connection isnt being made, or the slot isnt being called for some reason. If you are looking from the terminal than you should see the output from Qt that says cannot connect slots or whatever Qt says when it cant connect the slots. In that case it should give an error or warning. If it doesn't then it means the signal and slots are connected, but either the signal isn't emitted, or the slot is not called? which is weird.

I assume you are subclassing the UI, so maybe, just for the heck of it, try placing the connect again in the constructor of the subclass. Also make sure the slot is virtual, and not private.

You've prolly tried this, but in case you didnt, maybe try clean build?

Look @ the generated files and see if they are being generated correctly.

I don't know that's all I cant think of. Sorry.

I tried it and it works for me.
All I did was create a basic KDE app in KDevelop.

the kdbl.h header file:

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
#ifndef _KDBL_H_
#define _KDBL_H_

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <kmainwindow.h>

class KDoubleSpinBox;

/**
 * @short Application Main Window
 * @version 0.1
 */
class Kdbl : public KMainWindow
{
    Q_OBJECT
public:
    /**
     * Default Constructor
     */
    Kdbl();

    /**
     * Default Destructor
     */
    virtual ~Kdbl();
	
public slots:
	virtual void doubleChange(double v);
	
private:
	KDoubleSpinBox* spin;
};

#endif // _KDBL_H_


and kdbl.cpp

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
#include "kdbl.h"

#include <qlabel.h>

#include <kmainwindow.h>
#include <klocale.h>
#include <knuminput.h>
#include <iostream>

Kdbl::Kdbl()
    : KMainWindow( 0, "Kdbl" )
{
    // set the shell's ui resource file
    setXMLFile("kdblui.rc");

    new QLabel( "Hello World", this, "hello label" );
	
	spin = new KDoubleSpinBox( 0, 9.999, 0.001, 4.321, 3, this );
	
	connect(spin, SIGNAL(valueChanged (double)), this, SLOT(doubleChange(double)));
}

Kdbl::~Kdbl()
{
}

void Kdbl::doubleChange(double v)
{
	std::cout << "v: " << (int)(v * 10.0) << std::endl;
}

#include "kdbl.moc"


Good luck,

Latem
The march of progress:
C:
printf("%10.2f", x);
C++:
cout << setw(10) << setprecision(2) << showpoint << x;
Java:
java.text.NumberFormat formatter = java.text.NumberFormat.getNumberInstance();
formatter.setMinimumFractionDigits(2);
formatter.setMaximumFractionDigits(2);
String s = formatter.format(x);
for (int i = s.length(); i < 10; i++) System.out.print(' ');
System.out.print(s);

Krasu

Beginner

  • "Krasu" started this thread

Posts: 30

Location: Republic of Belarus

  • Send private message

3

Wednesday, May 4th 2005, 1:17pm

All my slots are virtual and private. I don't see the reason why they should be public. Qt doesn't print error to stdout, and generated sources looks ok:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
SQ_ImageBCG::SQ_ImageBCG( QWidget* parent, const char* name, bool modal, WFlags fl )
    : QDialog( parent, name, modal, fl )
{
     ...

    spinG = new KDoubleSpinBox( groupBox8, "spinG" );
    spinG->setMaxValue( 70 );
    spinG->setMinValue( 0 );
    spinG->setPrecision( 2 );

     ....

    connect( spinG, SIGNAL( valueChanged(double) ), this, SLOT( slotGSpinChanged(double) ) );
    init();
}

Krasu

Beginner

  • "Krasu" started this thread

Posts: 30

Location: Republic of Belarus

  • Send private message

4

Wednesday, May 4th 2005, 1:52pm

OK. I found the problem. It seemed that it's KDE bug. My KDE is 3.2.3 in MDK 10.0.

As you can see in knuminput.cpp in kdelibs sources

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
KDoubleSpinBox::KDoubleSpinBox( QWidget * parent, const char * name )
  : QSpinBox( parent, name )
{
  editor()->setAlignment( Qt::AlignRight );
  d = new Private();
  updateValidator();
}

KDoubleSpinBox::KDoubleSpinBox( double lower, double upper, double step,
                                double value, int precision,
                                QWidget * parent, const char * name )
  : QSpinBox( parent, name )
{
  editor()->setAlignment( Qt::AlignRight );
  d = new Private();
  setRange( lower, upper, step, precision );
  setValue( value );
  connect( this, SIGNAL(valueChanged(int)), SLOT(slotValueChanged(int)) );
}


In the first constructor signal valueChanged(int) is not connected, so initiliazing double spinbox in this case should look

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
class Class : public QVBox
{
    Q_OBJECT

    public:
        Class(QWidget *parent, const char *name) : QVBox(parent, name)
        {
            KDoubleSpinBox *spin = new KDoubleSpinBox(this, "double spin");
            spin->setRange(0.0, 7.0, 0.01, 2);
            spin->setValue(1.0);

            connect(spin, SIGNAL(valueChanged(int)), spin, SLOT(slotValueChanged(int)));
            connect(spin, SIGNAL(valueChanged(double)), this, SLOT(slotG(double)));
        }

        ~Class() {}

    private slots:
        void slotG(double v)
        {
            printf("V: %.2f\n", v);
        }
};


As you can imagine, uic didn't generate this additional connect(), so double spinbox didn't work. Now everything works ok. Maybe, it will be good to send bugreport ?

This post has been edited 2 times, last edit by "Krasu" (May 4th 2005, 3:30pm)


Latem

Beginner

Posts: 31

Location: New Brunswick, Canada

Occupation: Student/Programmer

  • Send private message

5

Wednesday, May 4th 2005, 3:19pm

hmm, I have KDE 3.2.3 too, with MDK 10.1 though. I'll take a look at my sources and see if there is anything different.

Maybe I am missing something, I still dont understand why would that slot be private?
Private members in a class can only be accessed by member functions and friends of that class. The whole point of private members is that derived classes do not get access to them.

Maybe the base class' slot is connected, and the derived class' slot is never connected to the signal, or something?

Latem
The march of progress:
C:
printf("%10.2f", x);
C++:
cout << setw(10) << setprecision(2) << showpoint << x;
Java:
java.text.NumberFormat formatter = java.text.NumberFormat.getNumberInstance();
formatter.setMinimumFractionDigits(2);
formatter.setMaximumFractionDigits(2);
String s = formatter.format(x);
for (int i = s.length(); i < 10; i++) System.out.print(' ');
System.out.print(s);

This post has been edited 1 times, last edit by "Latem" (May 4th 2005, 3:23pm)


Krasu

Beginner

  • "Krasu" started this thread

Posts: 30

Location: Republic of Belarus

  • Send private message

6

Wednesday, May 4th 2005, 3:26pm

Slots should be public, if anybody will need to call them directly (like QSlider::setValue()). I needn't it, so I created all slots private.

Quoted

I'll take a look at my sources and see if there is anything different


It's simple - just remove line

Source code

1
connect(spin, SIGNAL(valueChanged(int)), spin, SLOT(slotValueChanged(int)));


from my source code, and spinbox won't emit valueChanged(double) signal, and slotG(double) won't be executed.

Latem

Beginner

Posts: 31

Location: New Brunswick, Canada

Occupation: Student/Programmer

  • Send private message

7

Wednesday, May 4th 2005, 9:38pm

Yup, you're right its a bug.

http://bugs.kde.org/show_bug.cgi?id=89060

It was fixed in the 1.73 version of the file:

http://webcvs.kde.org/kdelibs/kdeui/knum…r1=1.72&r2=1.73

Latem
The march of progress:
C:
printf("%10.2f", x);
C++:
cout << setw(10) << setprecision(2) << showpoint << x;
Java:
java.text.NumberFormat formatter = java.text.NumberFormat.getNumberInstance();
formatter.setMinimumFractionDigits(2);
formatter.setMaximumFractionDigits(2);
String s = formatter.format(x);
for (int i = s.length(); i < 10; i++) System.out.print(' ');
System.out.print(s);