QString functions giving incorrect results on CentOS - c++

I am using C++ Qt Library and following code is working perfectly on Windows but not working on CentOS :
if(line.startsWith("[", Qt::CaseInsensitive))
{
int index = line.indexOf(']', 0, Qt::CaseInsensitive);
QString subLine = line.mid(index+1);
subLine = subLine.trimmed();
tokenList = subLine.split("\t");
}
else
{
tokenList = line.split("\t");
}
I have a line [ x.x.x.x ] something ../dir/file.extension and I want to ignore the [x.x.x.x] part while breaking line into tokens. I am using VC9 on windows to debug and its working fine.
Edit: i have removed mid() and used right() still same problem persists, working on windows but not on CentOS.
Edit: after debugging on linux using QMessageBox i have concluded that control is never going inside if block, i tried using if(line.data()[0] == '[') but same results.

Your code can be simplified.
line.remove(QRegExp("\\[\\s+\\d+\\.\\d+\\.\\d+\\.\\d+\\s+\\]"));
tokenList = line.split("\t");

Related

VivoxCore for Unreal Engine 4

Has anyone used VivoxCore for unreal engine 4 and know what this error means? I'm not able to really understand what this means. I've tried reading through the source code for vivox, as well as the documentation and that error code (1105) is mentioned nowhere. Also, the company which makes this does not respond to emails, and their public forum is not active. I've tried calling them, emailing them, using the public forum, reading online for answers, and I've found nothing, so stackoverflow is my last option. I hope someone here can help me.
LogVivoxVoiceChat: Warning: onConnectFailed server:https://vdx5.www.vivox.com/api2 error:SIP Backend Required (1105)
Here is my code:
VoiceChat = (FVivoxVoiceChat*)FVivoxVoiceChat::Get();
if (!VoiceChat->IsInitialized())
{
GLog->Log("Is not initialized, trying to initialize.");
VoiceChat->Initialize();
return;
}
if (!VoiceChat->IsConnected())
{
GLog->Log("Is not connected, trying to connect.");
VoiceChat->Connect(FOnVoiceChatConnectCompleteDelegate::CreateLambda([](const FVoiceChatResult& Result)
{
}));
return;
}
FString PlayerName = PlayerState->GetPlayerName();
FString LoginToken = VoiceChat->InsecureGetLoginToken(PlayerName);
if (!VoiceChat->IsLoggedIn())
{
GLog->Log("Is not logged in, trying to login.");
VoiceChat->Login(0, PlayerName, LoginToken, FOnVoiceChatLoginCompleteDelegate::CreateLambda([](const FString& LoggedInPlayerName, const FVoiceChatResult& Result)
{
}));
return;
}
FString ChannelName = "TestChannel";
EVoiceChatChannelType ChannelType = EVoiceChatChannelType::Echo; // Echo for testing.
TOptional<FVoiceChatChannel3dProperties> Channel3dProperties;
FString JoinToken = VoiceChat->InsecureGetJoinToken(ChannelName, ChannelType, Channel3dProperties);
VoiceChat->JoinChannel(ChannelName, JoinToken, ChannelType, FOnVoiceChatChannelJoinCompleteDelegate::CreateLambda([](const FString& JoinedChannelName, const FVoiceChatResult& Result)
{
GLog->Log("JOin Channel successful");
}), Channel3dProperties);
VoiceChat->TransmitToSpecificChannel(ChannelName);
This error means that you have an outdated SDK. The SDK included in UE4 is outdated: it is using backend version 4, but the actual version is 5.
Try disabling the Vivox Interface plugin if it's enabled.

VS 2015: Running Unit Tests from console, Selenium ChromeDriver problems

I'm 100% new here, and I'm not sure if anything else is expected before I post this question. But I didn't find anything about this exact issue when searching, so here goes:
I have a Solution framework using Selenium ChromeDriver for automating a web site, and an included Unit Test project for running the tests.
The tests can be run fine from the VS Test Explorer. But when I try running them from the VS console with
MSTest.exe /testcontainer:d:\Source\Workspaces\QA\Automation\Tests\bin\Debug\Tests.dll /resultsfile:d:\QA\testresults\autotests\regressiontests\tests.trx
i get these errors in the results file:
Test method Tests.BasicTests.Data.GetSiteData.GetMyElementId threw exception:
System.Exception: File not found
at Bytescout.Spreadsheet.Spreadsheet.LoadFromFile(String FileName, CacheType Cache, String Delimiter, Encoding Encoding, String Password)
at Bytescout.Spreadsheet.Spreadsheet.LoadFromFile(String FileName)
at TestData.Readers.ExcelByteScout.ExcelFindRows(String url, String sheetname, String value, Int32 col) in d:\Source\Workspaces\QA\FlowAutomation\TestData\Readers\EscelByteScout.cs:line 113
at TestData.SiteData.MyElements.GetElementId(String location, String element) in d:\Source\Workspaces\QA\Automation\TestData\SiteData\MyElements.cs:line 27
at Tests.BasicTests.Data.GetSiteData.GetMyElementId() in d:\Source\Workspaces\QA\Automation\Tests\BasicTests\Data\GetSiteData.cs:line 13
This is complaining about a Project -> Class in the solution which reads test data (user logins, CSS elements...) from an excel file.
and
Initialization method Tests.TestTests.OpenTests.OpenMyLabDrop2.Init threw exception. OpenQA.Selenium.DriverServiceNotFoundException: OpenQA.Selenium.DriverServiceNotFoundException: The chromedriver.exe file does not exist in the current directory or in a directory on the PATH environment variable. The driver can be downloaded at http://chromedriver.storage.googleapis.com/index.html..
at OpenQA.Selenium.DriverService.FindDriverServiceExecutable(String executableName, Uri downloadUrl)
at OpenQA.Selenium.Chrome.ChromeDriverService.CreateDefaultService()
at Common.Selenium.GCDriver.Initialize() in d:\Source\Workspaces\QA\FlowAutomation\Common\Selenium\GCDriver.cs:line 19
at FlowTests.Base.MyLabDrop2Test.Init() in d:\Source\Workspaces\QA\FlowAutomation\FlowTests\Base\MyLabDrop2Test.cs:line 15
this complains about a missing ChromeDriver.exe which is definetely not missing.
I'm not COMPLETELY new to VS and Selenium, but this I don't get, since the tests run fine from VS but complain about missing references from the console.
So I'm pretty sure there's something I'm missing when running the tests from the console, but what?
EDIT:
The relevant code from ExceByteScout.cs:
using System;
using System.Collections.Generic;
using Bytescout.Spreadsheet;
namespace TestData.Readers {
public class ExcelByteScout {
public static List<string> ExcelReturnXYZ(string url, string sheetname, string cell1, string cell2, string cell3) {
Spreadsheet document = new Spreadsheet();
document.LoadFromFile(url);
Worksheet worksheet = document.Workbook.Worksheets.ByName(sheetname);
List<string> cellvalues = new List<string>();
string name = worksheet.Cell(cell1).Value.ToString();
string user = worksheet.Cell(cell2).Value.ToString();
string pass = worksheet.Cell(cell3).Value.ToString();
cellvalues.Add(name);
cellvalues.Add(user);
cellvalues.Add(pass);
document.Close();
return cellvalues;
}
public static string[] ExcelFindRows(string url, string sheetname, string value, int col) {
Spreadsheet document = new Spreadsheet();
Worksheet worksheet = null;
List<string> values = new List<string>();
string[] userdata = null;
try {
document.LoadFromFile(url);
}
catch (System.Exception ex) {
System.Diagnostics.Debug.WriteLine(ex.Message);
throw;
}
try {
worksheet = document.Workbook.Worksheets.ByName(sheetname);
}
catch (System.NullReferenceException nrex) {
System.Diagnostics.Debug.WriteLine(nrex.Message);
throw;
}
int i = 0;
while (!worksheet.Cell(i, col).ValueAsString.Equals("")) {
if (worksheet.Cell(i, col).ValueAsString.Equals(value)) {
int rowcellcount = 0;
for (int y = 0; !worksheet.Cell(i, y).ValueAsString.Equals(""); y++) {
rowcellcount++;
}
userdata = new string[rowcellcount];
for (int x = 0; x < rowcellcount; x++) {
userdata[x] = worksheet.Cell(i, x).ValueAsString;
}
break;
}
i++;
}
document.Close();
return userdata
}
UPDATE:
The FileNotFound problem was due to a relative path.
But the ChromeDriver not found issue is a mystery. Specifically because this has worked before, in a different solution but with the exact same way of running the tests from the console.
Also, I'm standing in the /Debug folder of the project when I run MSTest.exe, and chromedriver.exe IS in this folder. I cannot see where else it needs to be?
File not found usually means that the file is not found on the location you expect it to be. This can happen because you run from an other path or the file is not copied.
Check the url before the line document.LoadFromFile(url); by Console.WriteLine(url). Then copy the excel to the correct location or fix the url.

Call a python code from WCF

I need to make a python code available as WCF for another application to access it. The python code was build by the data science team and have no ability to change it. I tried running the program as a process shell but it gives 'System.InvalidOperationException' exception.
I created the same program as C# console application and it works fine. The question is
a. Is this the right way to go about making python code available to another application (REST API is not an option).
b. What is the issue with my code.
public string ClassifyText(string value)
{
string textoutput = "";
string exeFileName = HttpContext.Current.Server.MapPath("~/python.exe");
string argName = HttpContext.Current.Server.MapPath("~/predictionscript.py");
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = exeFileName;
start.Arguments = argName;
start.UseShellExecute = false;
start.RedirectStandardOutput = true;
using (Process process = Process.Start(start))
{
using (StreamReader reader = process.StandardOutput)
{
string result = reader.ReadToEnd();
textoutput = result;
}
}
return textoutput;
}

How can I initialize an embedded Python interpreter with bytecode optimization from C++?

I am running an embedded Python 2.7 interpreter within my C++ project, and I would like to optimize the interpreter as much as possible. One way I would like to do this is by disabling my debug statements using the __debug__ variable. I would also like to realize any possible gains in performance due to running Python with bytecode optimizations (i.e. the -O flag).
This Stack Overflow question addresses the use of the __debug__ variable, and notes that it can be turned off by running Python with -O. However, this flag can obviously not be passed for an embedded interpreter that is created with C++ hooks.
Below is my embedded interpreter initialization code. The code is not meant to be run in isolation, but should provide a glimpse into the environment I'm using. Is there some way I can alter or add to these function calls to specify that the embedded interpreter should apply bytecode optimizations, set the __debug__ variable to False, and in general run in "release" mode rather than "debug" mode?
void PythonInterface::GlobalInit() {
if(GLOBAL_INITIALIZED) return;
PY_MUTEX.lock();
const char *chome = getenv("NAO_HOME");
const char *cuser = getenv("USER");
string home = chome ? chome : "", user = cuser ? cuser : "";
if(user == "nao") {
std::string scriptPath = "/home/nao/python:";
std::string swigPath = SWIG_MODULE_DIR ":";
std::string corePath = "/usr/lib/python2.7:";
std::string modulePath = "/lib/python2.7";
setenv("PYTHONPATH", (scriptPath + swigPath + corePath + modulePath).c_str(), 1);
setenv("PYTHONHOME", "/usr", 1);
} else {
std::string scriptPath = home + "/core/python:";
std::string swigPath = SWIG_MODULE_DIR;
setenv("PYTHONPATH", (scriptPath + swigPath).c_str(), 1);
}
printf("Starting initialization of Python version %s\n", Py_GetVersion());
Py_InitializeEx(0); // InitializeEx(0) turns off signal hooks so ctrl c still works
GLOBAL_INITIALIZED = true;
PY_MUTEX.unlock();
}
void PythonInterface::Init(VisionCore* core) {
GlobalInit();
PY_MUTEX.lock();
CORE_MUTEX.lock();
CORE_INSTANCE = core;
thread_ = Py_NewInterpreter();
PyRun_SimpleString(
"import pythonswig_module\n"
"pythonC = pythonswig_module.PythonInterface().CORE_INSTANCE.interpreter_\n"
"pythonC.is_ok_ = False\n"
"from init import *\n"
"init()\n"
"pythonC.is_ok_ = True\n"
);
CORE_MUTEX.unlock();
PY_MUTEX.unlock();
}
I solved this by setting the PYTHONOPTIMIZE environment variable prior to calling Py_InitializeEx(0):
/* ... snip ... */
setenv("PYTHONOPTIMIZE", "yes", 0);
printf("Starting initialization of Python version %s\n", Py_GetVersion());
Py_InitializeEx(0); // InitializeEx(0) turns off signal hooks so ctrl c still works
/* ... snip ... */

Visual Studio 2008 debugger wrong instruction executed position (Qt4, XML)

I have some part of code with which the debugger , when entering , starts stopping in lines with { braces.. suddenly jumps back to a blank line, and apparently is doing something (variables change), but the positions are different (there is some kind of weird offset back, skipping blank lines) and obviously i cannot see the contents of any variable.
Some facts:
I'm compiling on DEBUG
The code that fails falls inside more code which executes perfectly before.
The code does not work properly, but i double checked and it should. They are just 10 lines of code, exactly the same lines that the ones before, just changing variables names.
The debugguer stays crazy there, then out of the function in the caller function, and then returns to a normal state in the third parent function.
This code uses Qt 4.7 and QDomDocument functionality but works perfectly on other parts of the code. I added it to precompiled headers. (QXML)
I tried these with same errors:
Cleaning solution by hand or by visual
Cleaning all related Qt files (moc). Removed them, recompile, add again.
Changed the function to other part of the class.
Changed that piece of code to other part of the function.
Deleted file, removed from folder, compile, add it again and include the MOC.
Checked other threads. It is on the good thread.
Commenting the code makes it work perfect.
Here's the cursed code:
(...loaded file, check if worked)
// Assign file to dom document
QDomDocument doc("XML");
if (!doc.setContent(file)) {
file->close();
return;
}
// Root element (object)
QDomElement root = doc.documentElement();
QDomElement elt;
QDomElement elt2;
QDomElement elt3;
// NAME
elt = root.firstChildElement("name"); //-- works and debugs ok
if (!elt.isNull())
obj->setNameInfo(elt.text());
// TYPE
elt = root.firstChildElement("type"); //-- works and debugs ok
if (!elt.isNull())
obj->setTypeInfo(elt.text());
// REF NUMBER
elt = root.firstChildElement("ref"); //-- works and debugs ok
if (!elt.isNull())
obj->setRefNumberInfo( elt.text() );
// COLLECTION <collection><english>Text</english>...
elt = root.firstChildElement("collection"); //-- works and debugs ok
if (!elt.isNull())
{
elt2 = elt.firstChildElement("english");
if (!elt2.isNull())
obj->setCollectionInfo( elt2.text() );
}
// BRAND <mainBrand><id>id</id><web>url</web></brand>
elt = root.firstChildElement("mainBrand"); //-- works and debugs ok
if (!elt.isNull())
{
elt2 = elt.firstChildElement("id");
if (!elt2.isNull())
obj->setMainBrandIdInfo(elt2.text());
elt2 = elt.firstChildElement("web");
if (!elt2.isNull())
obj->setMainBrandUrlInfo(elt2.text());
}
// BRAND LIST <brands><brand><id>2</id><url>google</url></brand>...</brands>
elt = root.firstChildElement("brands");
{
QDomNodeList brands = elt.childNodes(); // AFTER THIS LINE, STARTS GOING WEIRD
if ( ! brands.isEmpty() )
{
elt2 = brands.at(0).toElement();
for ( ; !elt2.isNull(); elt2 = elt2.nextSiblingElement() )
{
QString id= "";
elt3 = elt2.firstChildElement("id");
if (!elt3.isNull())
id = elt3.text();
QString url= "";
elt3 = elt2.firstChildElement("url");
if (!elt3.isNull())
url = elt3.text();
obj->addBrandInfo(id, url);
}
}
}
// DESCRIPTION // THIS IS EXECUTED PERFECTLY BUT DEBUGGER IS STILL JUMPING AROUND
elt = root.firstChildElement("description");
if (!elt.isNull())
{
elt2 = elt.firstChildElement("english");
if (!elt2.isNull())
obj->setDescriptionInfo( elt2.text() );
}
... MORE CODE HERE. UNTIL THE END THE DEBUGGER WORKS WITH SOME WEIRD OFSET...
I discovered the answer after long hours of trials:
Reading the dissasembling of the code, we detected that Comment lines generated code, lines were not in the correct place, etcetera.
The problem comes with the encoding of the line breaks. The encoding of the file was not WINDOWS encoding. We had this set like this because we worked with MAC configurations, and we had some error messages concerning line breaks style. We choose one encoding that didn't fail since then, but now this error appeared.
The solution is to Save As... the file, selecting other options for the saving, and choose change encoding to Windows or whatever encoding you want to use.