0

I meet error about JSON data in QT, my code on Github if json data is a bit less, code can be compiled and run, but when json data is a bit bigger, code can't be compiled and run. You can clone my github code to test, I am sure to it can be compiled and run with short json, when you compile done, click DisplayDirAndFileDifferent button, you will see below picture:

enter image description here

When json is short, such as below, code can be compiled and run:

    const std::string json = R"([
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qmake.stash";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/adxintrin.h.F8695614109264BF.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/algorithm.85F84F593F617683.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/array.4A440D58C35C1B65.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/assert.h.1440D2C4BC469D57.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/atomic.46B98FDAFBC57939.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/bmiintrin.h.575071838DB7E543.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/cctype.6CAC01960A46CBE8.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/cerrno.D0366719F7F5D6B2.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/cfloat.D3E6A7BCFC6D7B8F.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/chrono.0EF46438A07D6958.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/climits.D8FE350A98C8E969.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/clocale.6DAA72D95FD7152A.idx";"LastModifiedTime": ""}
])";

But Json data is bigger, as like below, code can't be compiled and run:

    const std::string json = R"([
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qmake.stash";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/cmath.892CD3F82046EB21.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/concurrencysal.h.5DA0C09AED7DA192.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/corecrt.h.67FFEE19928F854D.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/corecrt_malloc.h.C0138CCDDEC903D5.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/corecrt_math.h.0390C374A34FAE6B.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/corecrt_memcpy_s.h.57108F1F96D1D502.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/corecrt_memory.h.65CCD44C1265E45E.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/corecrt_search.h.B43E2344530D0FBD.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/corecrt_share.h.DDB39811FDF689B6.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/corecrt_stdio_config.h.58436A96317F9ED9.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/cstddef.18387D969F572B40.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/cstdint.210D2F1E1255355E.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/cstdio.9E31F70803BFA76C.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/cstdlib.721BB85373461AF5.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/cstring.8985911536AFC237.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/ctime.1EFA885321907197.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/ctype.h.BC399C448EA6DADA.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/cwchar.1B862937C4978721.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/eh.h.F7CF178131C9CC77.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/emmintrin.h.6E9074898208EE3A.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/errno.h.FE9F83F635964CFD.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/exception.68221D83EEE0C979.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/filesystem.EEB58F510895B243.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/float.h.007015653F756B29.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/float.h.D55989CBB4E7EEA3.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/functional.F7983FBAA4462BCB.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/fxsrintrin.h.C52DDDDFB7A8B9DB.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/ia32intrin.h.3E30D2C597639933.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/immintrin.h.33FF6DAB2F686F5A.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/initializer_list.EE3DCE14C35AE786.idx";"LastModifiedTime": ""},





...
...
...
...
...
...
...
...
...
...




{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/intrin.h.411A625DDB615A10.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/intrin0.h.19F5FEEAE1E7457C.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/intrin0.inl.h.5D396B7ADE2D7A7B.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/iomanip.1D639BBCDBA1F3D0.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/ios.6E488EB20885070C.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/iosfwd.AE9C5D6643157A02.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/isa_availability.h.8CE89F7382834217.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/qimage.h.67597433C49CD802.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/qinputmethod.h.77B22054D6EE2814.idx";"LastModifiedTime": ""}
])";

Here is My test data, I think the data is not very big, because it just a section test data of I write application.

I Google search, but no find a approach to solve it. I need to compare modify date of directory and files to find what directory and files changed, directory and files is not fixed because user may be want to check some directory's file changed. See What do for I write application.

I read @BoP provided link Compiler Error C2026. See below picture:

enter image description here

I think my problem not only about string, but also about JSON format. What format should I write directory path to file and how I use it in json format.

How could I solve this problem? Thank you. JSON format can be very flexible, as long as the code works correctly..

First Update

When I use @drescherjm provided link code, I get error see below picture(But I think the error is every line without end with comma, but except for the last line, see Four Update that can work json format):

enter image description here

Second Update

When I use @Jarod42 answer, I get error see below picture:

enter image description here

Third Update

I provided link every line end with comma, but except for the last line, see below picture:

enter image description here

Four Update

When json data is short, progrma can be compiled and run. The json is:

    const std::string json = R"([
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qmake.stash";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/adxintrin.h.F8695614109264BF.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/algorithm.85F84F593F617683.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/array.4A440D58C35C1B65.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/assert.h.1440D2C4BC469D57.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/atomic.46B98FDAFBC57939.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/bmiintrin.h.575071838DB7E543.idx";"LastModifiedTime": ""}
])";

See below picture:

enter image description here

Tom
  • 417
  • 3
  • 10
  • 2
    The MS help page for [Compiler Error C2026](https://learn.microsoft.com/en-us/cpp/error-messages/compiler-errors-1/compiler-error-c2026?view=msvc-170) says that there is a limit of 16380 chars. And that the solution is to split it up in several smaller strings, that can then be concatenated. – BoP Jul 25 '23 at 13:42
  • @BoP Because I need to write directory path to file, then I need to read file by json format, Can you say more details? It seems that my approach is similar to approach in your provided link. – Tom Jul 25 '23 at 13:48
  • What the MS help *tries* to say is that each string has a size limit, but you can use several smaller strings instead. If you have two small strings `"Hello" "World"` close to each other in the source, they will be combined into one larger string. – BoP Jul 25 '23 at 13:56
  • Adjacent string literals will be concatenated automatically, it's a little known feature of C++. – john Jul 25 '23 at 13:58
  • @BoP But my problem not only about string, but also about JSON format. – Tom Jul 25 '23 at 13:59
  • @john But my problem not only about string, but also about JSON format. – Tom Jul 25 '23 at 14:00
  • 1
    This could help: [https://ideone.com/X7redR](https://ideone.com/X7redR) look at lines 14 and 15 – drescherjm Jul 25 '23 at 14:01
  • 1
    Have you read the link? either store data in a resource file, or split the string in smaller parts. – Jarod42 Jul 25 '23 at 14:02
  • That is a good point a Qt resource file would work great for this. – drescherjm Jul 25 '23 at 14:02
  • @Jarod42 Yes, I read the link, I need to write directory path to file, then I need to read file by json format. – Tom Jul 25 '23 at 14:03
  • The question is why can't you do what the link told you to do? What is stopping you from breaking the string up in multiple parts? I showed you an example @ ideone. If that is too painful, the Qt resource file example is probably your best bet. And that would not require the string to be broken up. – drescherjm Jul 25 '23 at 14:04
  • 1
    Error is because of limitation of msvc compiler about literal C-string. They propose one alternative solution (resource file (which is easy with Qt)) and a work-around (concatenate adjacent split strings). – Jarod42 Jul 25 '23 at 14:06
  • @drescherjm Every line without comma seem to can't work in my github code, it get json format error. – Tom Jul 25 '23 at 14:11
  • *"I think my problem not only about string, but also about JSON format."* Have you tried proposed solutions about strings, and why do you think it is about json format? – Jarod42 Jul 25 '23 at 14:11
  • @Jarod42 Before I get error when every line without comma, I try to use again your code. – Tom Jul 25 '23 at 14:13
  • @Jarod42 I try to use you provided link, but I get error, please see my updated question. – Tom Jul 25 '23 at 14:18
  • Not my link. And we don't know how you split your string, you might have typo (as missing comma... – Jarod42 Jul 25 '23 at 14:23
  • @Jarod42 sorry, I see error. I changed my answer. – Tom Jul 25 '23 at 14:24
  • If the json data requires a `,` on every line even the one before `]` you should add one to @Jarod42's answer. I use xml in Qt so far and not so much with json. – drescherjm Jul 25 '23 at 14:26
  • @drescherjm requires a comma , is in https://stackoverflow.com/questions/50021468/make-tree-folder-from-qtreeview-or-qtreewidget answer's code. But if without comma can solve problem is also good. – Tom Jul 25 '23 at 14:39
  • [OT]: temporary objects should not be versioned. – Jarod42 Jul 25 '23 at 16:06
  • @Jarod42 "temporary objects should not be versioned" about this, I don't understand well, what this mean? I now test json data, do you have a better approach/method? – Tom Jul 25 '23 at 23:01
  • I go in you github repo, and whole directory `build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug` should not be versioned (that directory might be in [.gitignore](https://git-scm.com/docs/gitignore). – Jarod42 Jul 26 '23 at 09:41
  • @Jarod42 I understand what you mean. Put the files that don't need to be tracked for changes in the gitignore. Thank you. – Tom Jul 26 '23 at 10:12

1 Answers1

2

Error is because of limitation of msvc compiler about literal C-string. They propose one alternative solution (resource file (which is easy with Qt)) and a work-around (concatenate adjacent split strings).

For the workaround, it would be something like:

    const std::string json = R"([
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qmake.stash";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/adxintrin.h.F8695614109264BF.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/algorithm.85F84F593F617683.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/array.4A440D58C35C1B65.idx";"LastModifiedTime": ""},
)" // First part
R"(
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/assert.h.1440D2C4BC469D57.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/atomic.46B98FDAFBC57939.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/bmiintrin.h.575071838DB7E543.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/cctype.6CAC01960A46CBE8.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/cerrno.D0366719F7F5D6B2.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/cfloat.D3E6A7BCFC6D7B8F.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/chrono.0EF46438A07D6958.idx";"LastModifiedTime": ""},
...
...
...
)" // other parts

R"({"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/QHBoxLayout.B54878B25703D6EF.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/QHeaderView.5F173F2D6020F3BC.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/qheaderview.h.9D687AEA36A2B403.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/qicon.h.8DA53B9D01FED295.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/qimage.h.67597433C49CD802.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/qinputmethod.h.77B22054D6EE2814.idx";"LastModifiedTime": ""}
]
)"; // Last part

As you use Qt, I really suggest to use resource file (.qrc) instead.

See their help page

Jarod42
  • 203,559
  • 14
  • 181
  • 302
  • I use your code get error, please see my updated problem. – Tom Jul 25 '23 at 14:23
  • @Tom: Assuming original string was correct, you might have introduced "typo" during the split. – Jarod42 Jul 25 '23 at 14:26
  • As debugging purpose, write the string into a file, and validate the file content with any json validator. – Jarod42 Jul 25 '23 at 14:28
  • Please see my second third and third update about every line end with comma. – Tom Jul 25 '23 at 14:35
  • You use `;` instead of `,` to separate field (Error: Parse error on line 2: ...-Debug/.qmake.stash" **ERROR>; – Jarod42 Jul 25 '23 at 14:40
  • You have same issue with your short json... – Jarod42 Jul 25 '23 at 14:42
  • "You have same issue with your short json", you are wrong, about this please see my four updated problem. About "You use ; instead of , to separate field (Error: Parse error on line 2: ...-Debug/.qmake.stash" ERROR>; – Tom Jul 25 '23 at 14:59
  • Now that your too long string is fixed, open a new question about json issue (and there, you have to show how you read your ("invalid") json). – Jarod42 Jul 25 '23 at 15:04
  • This question I brought has the JSON tag. At the begin, I say short json can work, but long json can't work. – Tom Jul 25 '23 at 15:13
  • I tried your git repo, and the split way works, once placeholder `...` removed, and typo (missing `]`) fixed, It even works with the big string, split by `)" R"(` in the lines spot by compiler. – Jarod42 Jul 25 '23 at 16:22
  • 1
    See https://pastebin.com/TxqJGV9C – Jarod42 Jul 25 '23 at 16:29
  • https://pastebin.com/TxqJGV9C, code in this link can be compiled and run, that is very good. Can you explain more details in your answer? How can I use it better? – Tom Jul 25 '23 at 23:07
  • The difference between pastebin and my answer is just the source json which is different. The one in question has `...` and possibly typo to close the array. – Jarod42 Jul 26 '23 at 09:45
  • I found. About `The one in question has ... `, can you make the ... more prominent? Or add a comment after ..., indicating that changes need to be made here. – Tom Jul 26 '23 at 10:01
  • It was from **your** data... – Jarod42 Jul 26 '23 at 10:19
  • I mean about `The one in question has ...` , can you make the ... more prominent `in your answer`? Or add a comment after ..., indicating that changes need to be made here(`in your answer`). If anyone encounters a similar problem in the future, they will be able to understand your solution more quickly. – Tom Jul 26 '23 at 10:33