开发者

Qt Creator places a '->' when I type '.' after a pointer object

开发者 https://www.devze.com 2023-03-15 05:07 出处:网络
I\'m creating a QNetworkAccessManager object in my project the standard way: QNetWorkAccessManager *manager = new QNetworkAccessManager (this)

I'm creating a QNetworkAccessManager object in my project the standard way:

QNetWorkAccessManager *manager = new QNetworkAccessManager (this)

and I am attempting to invoke the get() method but whenever I type the . after the manager object, Qt Creator is inserting a -> instead, so I end up with

manager->

when I want

manager.

Even when I concatenate manager and get() then move the cursor to the right place, Qt Creator still thinks I'm trying to access a sub-object of manager rather than invoke a method. I've been all over the 'O开发者_运维知识库ptions' dialogue but I can find any way of disabling this 'feature'. Does anyone know how to do it?


. and -> don't have anything to do with the difference between "sub-objects" or "methods". Both function members and field members are accessed in the exact same way. . is for accessing members of plain objects, and -> is shorthand for accessing members via pointers. In the usual case, a->b is the same as (*a).b.


You are programming in C#, but Qt requires you to program in C++. If manager is declared as a pointer, then manager. makes no sense in C++. Qt is simply trying to save you from yourself.


Like everyone else I don't understand why you think you need a '.' rather than '->'. But if this part of QtCreator's auto-completion can be disabled, it should be in Tools > Options > Text Editor > Completion. Then change the Activate Completion setting to Manual.

In earlier versions, auto-completion could not be disabled at all, but in newer versions you can make some adjustments at least. It works on 2.1.0 but if you have an earlier version it may not.


This is a convenient correction. manager is a pointer, so the -> operator is the correct way to access its members. Nice that Qt Creator has this much built-in intelligence.

0

精彩评论

暂无评论...
验证码 换一张
取 消