0

I've previously read that a line length in C++ source code files are limited means longer than a size couldn't be compiled. true yes? as you know in Qt creator many lines become long because of using Qt features, forexample for writing a string within a label it might be so long. so what will happen if our line became so long. Is it okay or some tricks should be done?

Novin Shahroudi
  • 620
  • 8
  • 18

1 Answers1

1

As tinman said, there is another question that might give you some info.

But consider this:

  • Qt has been used in many lines of code so far (and counting). So, except if you have a very special case you should not have to worry about this problem. If you were referring to a "long QLabel", you can still write code with line wraps and use the "+" operator.

  • Also, if your code is written in such a way that even the compiler chokes, I would not want to read or maintain your code ;)

Community
  • 1
  • 1
Derick Schoonbee
  • 2,971
  • 1
  • 23
  • 39
  • 1
    You can't use the + operator on C-string literals...only at run-time if they have been put into a string class. To break a string literal across lines just close the quote and open a new one on the next line: http://stackoverflow.com/questions/1135841/c-multiline-string-literal – HostileFork says dont trust SE May 15 '12 at 16:35
  • Well, QString has the + and << operator overwritten... and yes, you can use a plain string literal too :) – Derick Schoonbee May 15 '12 at 18:18
  • Right, QString has the operators...my only point is that if you're trying to pass a string literal as a parameter to something that takes a QString then in order to get that append you'd have to generate the object at runtime. So you'd end up writing `QString("first half of long string ") + QString("second half of long string")`. If you just do `QString("first half of long string " "second half of long string")` you can still break the line up between the constants *but* not pay for the append at runtime...the compiler puts all the characters in a row like a long constant would be. – HostileFork says dont trust SE May 15 '12 at 18:25
  • so is this okay: QString("first half of long string "\n "second half of long string") ? from "\n" I meant entering and writing the second string between quotes in a new line! – Novin Shahroudi May 16 '12 at 05:54
  • @Novin: Yup, as HostileFork mentioned. This is "more efficient" since it will be handled by the compiler as one string (compile time). – Derick Schoonbee May 17 '12 at 08:46