QString to TCHAR in QT

how I can copy a QString to a TCHAR value of a componet (Dll)?
In VC++ I used:
_tcsncpy(info.DeveloperID, m_strDeveloperID, 24*sizeof(TCHAR));
//info.DeveloperID = TCHAR

Open in new window

How it look in QT if m_strDeveloperID is a QString?
Ingo FoersterProgrammerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

This is quite similar to your 'TCHAT' issue, with the problem being that QString has 'std::string       toStdString() const' and 'std::wstring       toStdWString() const' as its members for this task. So, you either you need to provide cenvenience wrappers similar to 'tchat.h' or compile it conditionally like

#ifdef _UNICODE
_tcsncpy(info.DeveloperID, m_strDeveloperID.toStdWString().c_str(), 24*sizeof(TCHAR));
_tcsncpy(info.DeveloperID, m_strDeveloperID.toStdString().c_str(), 24*sizeof(TCHAR));

Open in new window

Ooops, alsmost forgot - the convenience wrapper could just be

TCHAR* QStringToTCHAR(const QString& qs) {
#ifdef _UNICODE
  return qs.toStdWString().c_str();
  return qs.toStdString().c_str();

// ...

_tcsncpy(info.DeveloperID, QStringToTCHAR(m_strDeveloperID), 24*sizeof(TCHAR));

Open in new window

And, last but not least: see the docs at http://doc.qt.io/qt-5/qstring.html
OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

Ingo FoersterProgrammerAuthor Commented:
so _tcsncpy is allowed in QT and works on all platforms like Linux, Mac and Windows?
As in your other Q: if you use 'tchar.h' (and Qt comes with it if you use MinGW), you can just #include and use it, it does nothing else but mapping the '_t*()' functions to their ANSI and UNICODE equivalents. That works on all platforms. All you have to take care of  for that to work is to add '#define _UNCIODE' (or provide that in your project settings) when compiling as UNICODE.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ingo FoersterProgrammerAuthor Commented:
Great and high professional help. Many thanks to jkr.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.