1,105,286 Community Members

Qt problem

Member Avatar
C++ programmer
Light Poster
28 posts since Jan 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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?

Member Avatar
ravenous
Practically a Master Poster
682 posts since Jul 2005
Reputation Points: 251 [?]
Q&As Helped to Solve: 112 [?]
Skill Endorsements: 13 [?]
 
0
 

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...

Member Avatar
Eagletalon
Junior Poster
135 posts since Mar 2011
Reputation Points: 34 [?]
Q&As Helped to Solve: 16 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
C++ programmer
Light Poster
28 posts since Jan 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

@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.

Member Avatar
Eagletalon
Junior Poster
135 posts since Mar 2011
Reputation Points: 34 [?]
Q&As Helped to Solve: 16 [?]
Skill Endorsements: 0 [?]
 
0
 

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"...

Member Avatar
C++ programmer
Light Poster
28 posts since Jan 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Yeah offcourse!

Member Avatar
C++ programmer
Light Poster
28 posts since Jan 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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.

Member Avatar
ravenous
Practically a Master Poster
682 posts since Jul 2005
Reputation Points: 251 [?]
Q&As Helped to Solve: 112 [?]
Skill Endorsements: 13 [?]
 
0
 

@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...

Member Avatar
Eagletalon
Junior Poster
135 posts since Mar 2011
Reputation Points: 34 [?]
Q&As Helped to Solve: 16 [?]
Skill Endorsements: 0 [?]
 
0
 

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"...

Member Avatar
C++ programmer
Light Poster
28 posts since Jan 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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?

Member Avatar
Eagletalon
Junior Poster
135 posts since Mar 2011
Reputation Points: 34 [?]
Q&As Helped to Solve: 16 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
C++ programmer
Light Poster
28 posts since Jan 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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.

Member Avatar
C++ programmer
Light Poster
28 posts since Jan 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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!

Member Avatar
ravenous
Practically a Master Poster
682 posts since Jul 2005
Reputation Points: 251 [?]
Q&As Helped to Solve: 112 [?]
Skill Endorsements: 13 [?]
 
1
 

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 :)

Member Avatar
C++ programmer
Light Poster
28 posts since Jan 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

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

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

ch=ch.unicode()+1;
}

Member Avatar
ravenous
Practically a Master Poster
682 posts since Jul 2005
Reputation Points: 251 [?]
Q&As Helped to Solve: 112 [?]
Skill Endorsements: 13 [?]
 
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.

Member Avatar
C++ programmer
Light Poster
28 posts since Jan 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Question Answered as of 2 Years Ago by ravenous and Eagletalon
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: