0
primaryColumnCombo->setMinimumSize(
        secondaryColumnCombo->sizeHint());

Above code can run normally. But from Qt's help, there are 3 types of setMinimumSize().

QSize   minimumSize () const
void    setMinimumSize ( const QSize & )
void    setMinimumSize ( int minw, int minh )

And here I think the 2nd type is executed. But it needs a QSize & as its argument, why in the code, it can accept a QSize?

Tom Xue
  • 3,169
  • 7
  • 40
  • 77

2 Answers2

2

I'm not sure I quite understand your question, if what you are asking for is just the difference between passing a parameter to a function as a const SomeType & versus just SomeType, there is plenty of documentation about this but here is a brief synopsis of when to use which...

myFunction(const SomeType &)

Pass a parameter as so when Copying is an expensive operation(and by expensive I mean... copying consumes lots of CPU resources and processing power).

myFunction(type)

Use when copying is not an expensive operation. Generally this is usually used for primitive types and copy-on-write objects.

stackunderflow
  • 10,122
  • 4
  • 20
  • 29
0

There's actually only 2 types of setMinimumSize. QSize minimumSize() const is an accessor which returns the current minimum size. It does not allow you to set the minimum size.

The first, void setMinimumSize(const QSize&), takes a QSize, which is essentially just a width and a height packaged together. It accepts the QSize by const reference, because that's the standard way for Qt's functions to accept objects. Details on why they might follow that practice be found in this answer.

The second, void setMinimumSize(int minw, int minh) takes a width and a height as a pair of parameters.

There's no difference between the two. They just provide two functions as a convenience, in case you already have a QSize to pass to it, or you already have a pair of integers. Your example is a case of the former, and it should work exactly as you expect.

Community
  • 1
  • 1
cgmb
  • 4,284
  • 3
  • 33
  • 60