Error in subclassing QAbstractSlider
-
What exactly do you mean?To set the scrollbar and give it the name of verticalScrollBar_z? If yes, this has been done
-
A proper way of subclassing widgets using ui forms is to choose one type that best ressembles your widget. In your case this is qslider. You give it a name you can remember myWidget and you right button click on it choose promote and give it the name of your subclass which is my_scrollbar (i would name it rather my_slider to make reading your code easier afterwards)
Then you can use it in your code like ui->myWidget.I suggest you read more about this approch in the docs.
Look for subclassing in Qt DesignerEdit :
" Try this link: ":http://doc.qt.nokia.com/4.7/designer-using-custom-widgets.html -
I have made this change to the code
@#ifndef SCROLLBAR_H
#define SCROLLBAR_H#include <QSlider>
class my_scrollbar : public QSlider
{
Q_OBJECTpublic:
my_scrollbar();void valueChanged (int);
signals:
void setValue (int value);
};#endif // SCROLLBAR_H@
But after choose the QSlider, my_scrollbar as Promoted class name and header file, then Qt Designer do not give me the choise of promote my_scrollbar. Do you know why? Do I must change something else?
-
I think you succeeded because you could set the class name and corresponding headerfile in Qt Designer.
Once promoted you cannot promote it again unless you un- promote it first.
Now the only thing you have to do is use it in your code like ui->myWidget. And you don't have t make an instance of your class anymore because you have it already.
-
You say that I do not to subclass my_scrollbar. I need just to promote myWidget, and use it in my code like this ui->myWidget.Also I have to use the
@connect(ui->verticalScrollBar_z,SIGNAL(valueChanged(int)),
this,SLOT(setValue(int)));@Had I understand it correct? Instead of QSlider could I use QScrollbar?
-
I didn't say that you don't have to subclass. I said you don't have to make an instance of your subclass anymore like you did in your mainwindow class.
You already have access to your slider that you subclassed by using
@Ui->myWidget@
Which points to your slider in your form.Edit:
I think you named your promoted widget :
@ui->verticalScrollBar_z@
So use this instead of my example. I was just explaining what to do using an example. i wasn't programming for you. -
I have used exactly the code I have included in the begin of this discuss. Also, I promoted verticalScrollBar_z as a QScrollBar with promoted class name and header file the my_scrollball. But still I get the same error. From what you said, it should work properly? Do you know what is the reason? I really cannot find my mistake.
-
What error do you get?
-
error C2065: ‘ui->’ : undeclared identifier
Is difficult to understand the procedure. Could you be more spesiphic, or give me a simple example? -
If you type @ui.@
Then ctrl + tab
What members can you use? Do you recognize the name you gave to your widget in Qt Designer? Then use it. What did you use? a QSlider? -
In the official Qt book :
bq. C++ GUI Programming with Qt 4
by Jasmin Blanchette; Mark Summerfield
If you google you should find it. Or you could use the docs .....Getting startedYou should read chapter 5 : Creating Custom Widgets
bq. Integrating Custom Widgets with Qt Designer
There the author explains with code and pictures the process of promoting widgets.