Click here to Skip to main content
15,919,245 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I do not understand why I am getting the error.
/mnt/A_BT_DEC10/A_MAY_9/A_APR9_MAR7_MAR19_CLEAN/A_BT_LIBRARY/A_DEC17_Bluetoothctl_Dialog_V1/mainwindow_bluewtoothctl_dialog.cpp:55: error: expected expression

all I want is to assign plain text to Qt version of string.
C++
QString Commands = 
        "
        list		List available controllers
        show		Controller information
        select		Select default controller
        devices		List available devices
        paired-devices	List paired devices
        system-alias	Set controller alias
        reset-alias	Reset controller alias
        power		Set controller power
        pairable	Set controller pairable mode
        discoverable	Set controller discoverable mode
        discoverable-timeout	Set discoverable timeout
        agent		Enable/disable agent with given capability
        default-agent	Set agent as the default one
        advertise	Enable/disable advertising with given type
        set-alias	Set device alias
        scan		Scan for devices
        info		Device information
        pair		Pair with device
        cancel-pairing	Cancel pairing with device
        trust		Trust device
        untrust		Untrust device
        block		Block device
        unblock		Unblock device
        remove		Remove device
        connect		Connect device
        disconnect	Disconnect device
        ";


What I have tried:

No problem with comma separated items

C++
QString Command_Test = " list	,	List available controllers";
Posted
Updated 22-May-24 6:05am
v2
Comments
[no name] 22-May-24 11:40am    
My objective is to assign plain text, as stated.
AFTER I get the assignment I like to analyze the text and extract specific.
I am trying to avoid massaging the text BEFORE, as you did.
It is impractical to do so in the long run.
Thanks for your suggestion...
k5054 22-May-24 12:23pm    
1: I think maybe you replied at the wrong place, and this should be a reply to one of the solutions, below
2: If this is a static string, why go through the work of extracting things later? Why not just create your extracted objects at the get go? Seems like unnecessary work to me, with the added possibility of having to debug later. Creating the aggregate string from those objects shouldn't pose too much difficulty.

C++ provides raw string literals: String literal - cppreference.com[^].
 
Share this answer
 
Comments
k5054 22-May-24 12:15pm    
My 5.
I always forget about raw string literals. :(
CPallini 22-May-24 13:21pm    
Thank you very much.
PLease try:
C++
QString Commands = 
        "list		List available controllers\n"
        "show		Controller information\n"
        "select		Select default controller\n"
        "devices		List available devices\n"
        "paired-devices	List paired devices\n"
        "system-alias	Set controller alias\n"
        "reset-alias	Reset controller alias\n"
        "power		Set controller power\n"
        "pairable	Set controller pairable mode\n"
        "discoverable	Set controller discoverable mode\n"
        "discoverable-timeout	Set discoverable timeout\n"
        "agent		Enable/disable agent with given capability\n"
        "default-agent	Set agent as the default one\n"
        "advertise	Enable/disable advertising with given type\n"
        "set-alias	Set device alias\n"
        "scan		Scan for devices\n"
        "info		Device information\n"
        "pair		Pair with device\n"
        "cancel-pairing	Cancel pairing with device\n"
        "trust		Trust device\n"
        "untrust		Untrust device\n"
        "block		Block device\n"
        "unblock		Unblock device\n"
        "remove		Remove device\n"
        "connect		Connect device\n"
        "disconnect	Disconnect device";
 
Share this answer
 
v2
Comments
k5054 22-May-24 11:59am    
White space is acceptable when concatenating a string constant, so you can remove the trailing \, and to OP probably wants a trailing newline (\n) as well. Perhaps even some initial spaces too.

To the OP: multi line string constants are not valid in C/C++.
Ștefan-Mihai MOGA 22-May-24 12:53pm    
Thank you! I've improved my solution :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900