Important: Please read the Qt Code of Conduct -

Qt text editor error checking

  • Hello, I just started learning how to use Qt a few days ago after being in Visual Studio for a while. Is there any way to make the Qt code editor display current errors so I don't have to wait to run it to find out? For instance, say I misspell a variable name, is there a way to make the editor underline or something so I know it is incorrect.

    Probably an easy question, thanks!

  • Moderators

    Yeap, that can be done (we do it in Qt Creator). It takes quite a bit of code though to find the errors, highlighting them is not too hard;-)

  • Sorry, I don't know if I understand your response. Can you do that like in visual studio then or not? And if so, can you let me know how? Thanks.

  • Moderators

    The text editor allows you to do all kinds of highlighting. But it handles the rendering part only: Drawing text in different colors, etc. for you. You might want to do some customization to the rendering (at least we do that in Qt Creator AFAIK), but you can get pretty far without.

    The tricky is part is to find out what to highlight though. Qt has no out-of-the-box functionality to help with these tasks: Highlighting programming errors requires your code to understand the programming language to find those errors first. That is highly domain specific task and does not belong into a general-purpose library like Qt.

    It can be done of course (again: Check Qt Creator:-), but it can take a lot of code to do. This of course depends a lot on what you want to highlight and how correct you want that highlighting to be. It is e.g. rather easy to highlight a variable that is only seen once in one text file as incorrect, but much harder to make sure this variable is not a global variable included by some system header file included by one of the files included in the file you are currently editing. It is also easy to highlight all keywords of a language, but much harder to highlight only those keywords that are used wrongly.

    If you want to look at Qt Creator as an example of what you want to do: Check the plugins containing "cpp" and "editor" in src/plugins.

  • Okay, I see what you're saying. I had no idea it was such a big task. That sounds like it may be a little past my expertise right now but I'll definitely look into it. Maybe I'll learn something. Thanks again!

  • Moderators

    I do not know what you want to do, but maybe you could plug into an existing piece of software? Most IDEs are extensible by plugins. Maybe you could find some existing IDE that is close to what you want to have and implement only the missing parts?

  • What I mean is, if there is an error in my code like a misspelled variable name or misspelled function name, the IDE would let me know before I compile it. I don't mean a run-time error, just a spelling error really.
    For example, in the Qt editor, say you put 'int x = 5;' somewhere in the code. It immediately underlines x and says 'unused variable'. However if you write 'x = 5;' somewhere in the code. No errors are shown until you compile it, and then it says 'x: undeclared identifier' in the 'issues' window. Is there a way, or even a plug in if necessary, to tell me this error before I try and compile the project? I suppose I was spoiled in Visual Studio but it seems like if the Qt IDE can show the first error I described, it should be able to show the second.

  • Moderators

    Hey, you are right! Did you check whether there is a bug report for that?

    I unfortunately do not really know the code behind Creator's code model, so I can't give pointers on how to fix this. If you are interested in fixing this yourself: All the devs hang out in IRC, most of them during european business hours (#qt-creator on freenode network) and are willing to point you into the right direction;-)

  • Oh, so you mean they should be highlighted already without me having to do anything? That's interesting. I'll look into that. Thanks!

  • Moderators

    I am not sure whether creator used to do this or not. In any case it is worthwhile doing a bug report, as the bug tracker is the best way to request features, too.

Log in to reply