Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. Chinese
  4. 为什么成员变量(非指针)初始化时,可以用指针赋值?
Qt 6.12 LTS is out! See what's new in the release blog

为什么成员变量(非指针)初始化时,可以用指针赋值?

Scheduled Pinned Locked Moved Solved Chinese
2 Posts 2 Posters 2.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    UUll
    wrote on last edited by
    #1

    PixPin_2025-10-31_10-36-28.png
    PixPin_2025-10-31_10-36-52.png
    如图片所示,正常编译而没有报错,这不合理啊!

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bonnie
      wrote on last edited by
      #2

      这不是赋值,是构造函数的参数啊,QTimer的构造函数是QTimer(QObject *parent = nullptr),你这样就把这个new出来的QTimer作为它的parent传给它的构造函数了,编译当然没问题,在运行时因为m_timer应该会早于它的parent被销毁所以也没有问题

      1 Reply Last reply
      0
      • L Liang Qi has marked this topic as solved on

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt
      • Unsolved