Hi, when calling this:
the program crahes without a reason. im sure the tmp has a " "Qt Code:
std::string final = tmp.substr(tmp.find(" "), tmp.length());To copy to clipboard, switch view to plain text mode
PS:
when i debug i get seg fault
Hi, when calling this:
the program crahes without a reason. im sure the tmp has a " "Qt Code:
std::string final = tmp.substr(tmp.find(" "), tmp.length());To copy to clipboard, switch view to plain text mode
PS:
when i debug i get seg fault
Last edited by Fallen_; 17th September 2010 at 05:30.
Possible problems:
tabs = 0
m_chan = 0
if socket is a pointer, it can be 0 too.
So, do a check on all pointers, or check your backtrace to find which pointer is 0
already did, nothing wrong
Post your backtrace.
Did you mean this?:
Signal name: SIGSEGV
Signal meaning: Segmentation fault
if not:
http://pastebin.com/R5uubZPf
---The text that you have entered is too long (46227 characters). Please shorten it to 10000 characters long.
anything else?
No, that is the compiled code of a QWidget::setParent function.
But it might get us closer to the error.
If your program fails in this function, you're creating a widget with a non valid parent.
I guess Channel is a widget?
And the first argument in the constructor is the parent?
Does "this" exist?
Channel is a widget yes, and "this" exist while calling it and yes the first arguemnt is QWidget
I would love to see the backtrace.
What system are you using? Window, Linux, MacOs, ... ?
What IDE are you using? Qt Creator, ... ?
Windows, Qt creator (to debug), and Qt Command Line to compile. how do i get the backtrace?
In Qt Creator, in stead of running the program normally, run the program in the debugger.
When it crashes, go to the stack view (should be the list on the left I think), it should contain the backtrace.
nope, cant see anything
I'm not in front of my computer at the moment so I can't help you with that at the moment.
But to give some more information:
The backtrace is a list of functions that were the last functions being run in your program.
The very last function in this list usually contains the crash. You can then follow the list of functions to see where the problem first occured.
Segmentation faults happen when you try to access memory that you should never access (like the memory segment of the kernel). Most of the time this happens when the pointer to an object is 0.
The stack list should be the list on the left in the debugging section of Qt Creator.
I agree that running in a debugger will be the fastest solution here. Another point: you never check the results of your "find" operation. Despite your insistence that there's a space to be found in the string, it's poor form not to check that the operation actually succeeded.
You could also simply print the results of each line shown to cerr, which would at least isolate the line that is causing the problem. Printing out tmp prior to the string manipulations would also shed some light.
ok i have made something like this:
and then read->append(buffer) and it worked but i commented out the:Qt Code:
if(sscanf(tmp.c_str(), "/join %s", buffer) > 0) {To copy to clipboard, switch view to plain text mode
so its something wrong with them.Qt Code:
To copy to clipboard, switch view to plain text mode
Is there any specific reason that you are using C strings and std::string instead of QString?
Please show us the constructor of Channel.
Qt Code:
{ read->setReadOnly(true); layout->addWidget(read); layout->addWidget(write); layout->addWidget(send); setLayout(layout); setWindowTitle(name.toLatin1()); connect(send, SIGNAL(clicked()), this, SLOT(sendM())); read->append("Welcome to " + name + "\n"); }To copy to clipboard, switch view to plain text mode
buffer is a QString. Print it out and see what it contains before using it.
Or - still by far the best bet - run your code through a debugger and isolate the problem in a minute or two.
Could you print the value of buffer before calling the constructor?
By the way, if you want to extract the argument to your "/join" command, you can do it this way:
Qt Code:
// assuming QString tmp holds the complete line (i.e. "/join #qt") // detect '/' followed by an alphanumeric string followed by a whitespace followed by some other text if(commandRx.exactMatch(tmp)){ // we have found a command cmdName = cmdName.toLower(); if(cmdName == "join") { if(channel.startsWith("#")) { joinChannel(channel.mid(1)); // join everything starting with '#' } } } else if(cmdName == ... ) { ... } ... }To copy to clipboard, switch view to plain text mode
man i already made it to get the text, now when i do something like this:
it works but i need it to append a text in the text edit of the channel, when i call printText (from the channel class) from another function it doesnt do anything:Qt Code:
To copy to clipboard, switch view to plain text mode
any ideas?Qt Code:
Channel *chan = new Channel(this, channel.c_str(), socket, tmp); chan->printText(tmp);To copy to clipboard, switch view to plain text mode
I'm aware of it, the point is you are doing it with a C api that is cumbersome and error prone.
I have no idea what you mean. What is printText(), what other function and what was it supposed to do?it works but i need it to append a text in the text edit of the channel, when i call printText (from the channel class) from another function it doesnt do anything
Bookmarks