I have designed a dialog in Qt designer and I want to use the name of each child widget for some coding in cpp file. But the names I have given to buttons etc in Qt designer are not working as pointer.More over their names in ui_mydialogname.h are not the one i gave them in Designer. Even when I use the name assigned to them the suggestion window won't popup. What do I do?

Do you have a simple example of the problem that you have? Post some of your code. It's hard to suggest anything when no-one can see how you're using things...

Ey mate... I use QT myself... how do you compile your program into a VCproject?

I personally use qmake command in command prompt, if this is how you do it as well just run it again with the application closed and it should update all the ui changes into your project

@Eaglealon I compile my program in Qt IDE using play button or F5 key.Bro its just a drag and drop program in which i gave names to buttons but when i try to use those buttons using code in the program .cpp file, i can't use them as pointers or objects.


@Ravenous Bro its just a drag and drop program in which i gave names to buttons but when i try to use those buttons using code in the program .cpp file, i can't use them as pointers or objects.

I believe the issue is that the controls you have added to the ui are not named in the same way in the ui's header file... you can try to rename them manually if you cant recompile the header

And I am sorry to ask this, but are you certain you changed the name in the correct field? QT Designer has 2 fields namely "Object Name" and "Text"...

another question is: Why do we use ui->widget->required function syntax in Class cpp file in order to access a widget function. why isn't this syntax allowed widget->required function.

@Ravenous Bro its just a drag and drop program in which i gave names to buttons but when i try to use those buttons using code in the program .cpp file, i can't use them as pointers or objects.

It's the "use those buttons using code in the program" part that I was asking to see.

Why do we use ui->widget->required function syntax in Class cpp file in order to access a widget function. why isn't this syntax allowed widget->required function

The behaviour of Qt Designer is to produce a class in a namespace called Ui that contains all the stuff that you made in the designer. The class that you're editing the cpp file for will have a private member of this automatically generated type, called ui . To do things with the widgets that you made in Designer, you have to access them through the ui member of your class.

There is another way to use Qt that uses inheritance, and then you can do the things that you mentioned. I don't know if designer can be adjusted to use this pattern though, I just use the default one.

If you post the code that you're trying to write, then people might be able to offer some advice...

What I usually do is I inherit my main class from the UI, that way I can run the functions as follows:

setupUi(this);

QString text;

text = this->lineEdit->text();

the whole thing with the "ui->member->function" is to be able to handle multiple forms better, that way you need to specify the parent of the widget to access the correct one...

its like working in a database in SQL, you can either use "SELECT * FROM MyTable" or you can use "SELECT * FROM MyDatabase.dbo.MyTable"...

if i use a pointer created in class and dynamically allocate memory to it, would i have to deallocate its memory myself or it would be deallocated automatically? Similarly if i create a pointer inside a function(so its function will limited to the function) and allocate memory to it, would i have to deallocate its memory myself or it would be deallocated automatically?

Well theoretically if you say "pointer = new class()" and you allocate memory to it then yes you would have to...

the core programming stays C++, only C# users are blessed with the garbage collecter

well in qt programming all the time we allocate dynamic memory to pointers. Most of the people say when the parent object is destroyed, its child widget having pointers are also destroyed. And this happens only when the program is closed. So my question is this true and if this definition also goes for a function's local pointers.

I can't understand why primaryColumnCombo setting its minimum size by the ideal size of the secondaryColumnCombo, when the SecondaryColumnCombo is the copy of PrimaryColumnCombo?

primaryColumnCombo->setMinimumSize(secondaryColumnCombo->sizeHint());
And how does "ch" will become equal to "last"?

QChar ch = first;
while (ch <= last)
{
primaryColumnCombo->addItem(QString(ch));

ch = ch.unicode() + 1;
}
And in QString(ch) is "ch" is type getting typecasted!

So my question is this true and if this definition also goes for a function's local pointers.

No, you still have to call delete on anything that you choose to new in a function. In fact, I think that Qt only deletes certain pointers and only if you have the right flags specified, for instance by calling setAttribute( Qt::WA_DeleteOnClose ) in the constructor of your Q_OBJECT

I can't understand why primaryColumnCombo setting its minimum size by the ideal size of the secondaryColumnCombo

I think that this is an example of how to make an expanding sort dialog from the book "C++ GUI Programming with QT 4" or one of its predecessors. Correct? If so, it explains in the text that the secondary and tertiary combos have the default text "none" in them, which is the widest entry of any of the three combos on the dialog. To prevent the primary combo from resizing in an ugly way when the "More" button is clicked, the primary combo takes its hint from the (wider) secondary combo.

And how does "ch" will become equal to "last"?

If this is indeed the example that I mentioned, then last is passed in as an argument to the setColumnRange function.

And in QString(ch) is "ch" is type getting typecasted!

Yes, it is. The addItem member of QComboBox takes a reference to a QString as its argument, not a QChar . However, QString has a constructor that takes a QChar so you can do a kind of typecast by making a temporary QString like you see here.

This seems to be drifting away from your original question. If you have solved that issue, you should mark this thread as "solved" and start a new thread for additional questions :)

+1 ravenous. Thanks alot. Can i do like this

QString ch=first; // where first is also QString

while(ch<=last)
{
......

ch=ch.unicode()+1;
}

Can i do like this
QString ch=first; // where first is also QString

I don't think so, since the ch=ch.unicode()+1 line probably won't work as expected for a QString , compared to a QChar . It's also possible that your ch could be changed later in the code to be something random. It's not likely in this code because it's a very small chunk of code and you can see everything that's going on. However, it's not a pattern that I would recommend that you get into. It's safer to keep the variable as a QChar and only convert to a QString when required, as the original code does.

+1 ravenous. Thanks alot.. please visit my other thread QT on android

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.